Thursday, August 11, 2011

How to set different page margins within the same chapter in LaTeX

Update: 24 Aug 2011M/ 24 Ramadan 1432H, Ra.
8 Ramadan 1432H

My thesis has fixed (consistent) margins throughout the whole document, so it's no problem to set the margins once and leave it be.

But what if a thesis has different margins for different pages within the same chapter? -- This problem most probably hits book-writers too.

For instance, it is required the top margin for
the page-with-"Chapter" be 5cm (see Pic 1 and Pic 5), while
the page-without-"Chapter" be 3cm (see Pic 2 and Pic 6).

As for the rest,
2.5cm for the bottom margin (see Pic 6),
3.8cm for the left margin (see Pic 5), and
2.5cm for the right margin (see Pic 5).

Pic 1 - Opening page (page-with-"Chapter").


Pic 2 - Succeeding page (page-without-"Chapter").


Tools

Template
If you want to use the same template i'm using (though mine has been heavily modified by now), you can get it here:
INSPEM -- Institute For Mathematical Research.

From there, look for this link to download the template:
UPM Thesis Template (Versi BI)

And download the guide too:
User Guide for UPM Thesis Template

You must first modify the template as directed by the guide before proceeding to use the template.

Dummy text
As for the text, simply go to this link:
Lorem Ipsum - All the facts - Lipsum generator
and generate a few paragraphs of dummy text.


Steps

1. Add the following commands to the list of packages in your main file. In my case, it will be the UPMthesisEnglish.tex file, see Pic 3.

\usepackage[top=3.0cm, bottom=2.5cm, left=3.8cm, right=2.5cm]{geometry}

\usepackage{titlesec}

Pic 3 - Adding the commands in the UPMthesisEnglish.tex file.


The geometry package will be used to set the margins for the page-without-"Chapter" page (see Pic 2).

If your thesis has a fixed margin throughout the whole document, the first command line (command line numbered-1 in Pic 3) is enough!

Also, you can use the first command line to override margin settings (and only the margin settings, nothing else) in the *.cls file. In my case, it will be the UPMthesisEnglish.cls file. i don't know how others' *.cls file looks like but mine is really messy + complicated.

The titlesec package will be used to set the margins for the page-with-"Chapter" page (see Pic 1). Basically we will vertically offset the title.


2. Add the following commands to the relevant sub-files. In my case, i'm using my own Chapter4.tex file. You can use the generated dummy text in your file.

\titlespacing*{\chapter}{0pt}{1.5cm}{1cm}

\titleformat{\chapter}[display]{\normalfont\bfseries\centering}{\MakeUppercase\chaptertitlename\ \thechapter}{0pt}{\normalfont\uppercase}

As seen in Pic 4, put the command lines at the topmost of the file, before these lines:

\chapter{\textbf{Methodology}}\label{method}
\thispagestyle{empty}

Pic 4 - Adding the commands in my Chapter4.tex file.


{0pt}
  • is the horizontal spacing between the left margin and the  title.

{1.5cm}
  • is the vertical spacing preceding the title (which will vertically offset the title, which in turn will offset the succeeding texts as well)
  • the offset is combined with the top margin of page-without-"Chapter"
  • 3.0cm (top margin of page-without-"Chapter")
    + 1.5cm (vertical offset)
    = 4.5cm --> 5.0cm (top margin of page-with-"Chapter")

{1cm}
  • Vertical spacing between the chapter title and the next text. In this case, the vertical space between the word METHODOLOGY and the first paragraph (see Pic 1).

To read further about the formatting, download the file:
titlesec.pdf.
  • \titleformat is on page 4.
  • \titlespacing* is on page 4 and 5.

Also, read here:


3. Compile your file. Make a physical print of the *.pdf file. In my case, it is the UPMthesisEnglish.pdf file. Then measure the margins in the printed document. Otherwise use a virtual ruler. If your virtual ruler needs calibration, go to iRuler.net - Online ruler.

Unless you have nuclear-reactor-precision confidence with your method, DO NOT measure the margins by slapping on a physical ruler against the screen... like i did *oh! the shame of it*. The measurements will probably be off.

After learning from my mistake, i'm using the Screen Ruler now. See Pic 5.

Pic 5 - Virtual ruler. Screen Ruler.


Where to measure?

To measure the top margin of a page-with-"Chapter" page, go to any page with a chapter. See Pic 6.

Pic 6 - Top margin for the page-with-"Chapter" page. Also shown in this pic are the left and right margins. This pic is the superimposed result of three separate pics.


To measure the top margin of a page-without-"Chapter" page, find a page that does not have a break in paragraph (one part of the paragraph on the previous page, another part of the paragraph on this page), i.e., the page starts with a paragraph. See Pic 7.

Pic 7 - Top margin for the page-without-"Chapter" page. Also shown in this pic is the bottom margin. This pic is the superimposed result of two separate pics.


To measure the bottom margin, find a page that does not have a break in paragraph (one part of the paragraph on this page, another part of the paragraph on the next page), i.e., the page ends with a complete paragraph. See Pic 7.

The reason for not wanting a paragraph that breaks across pages is because, the line spacing (singlespace/doublespace/etc) will effect your measurement.

As for the left margin and right margin, they can be measured on any page you like. See Pic 6.


Reference

http://en.wikibooks.org/wiki/LaTeX/Page_Layout
http://www.ctex.org/documents/packages/layout/titlesec.pdf


Note

i don't know how this process will affect the ToC (Table of Contents), and other pages.

Thank you to the email sender(s).

No comments:

Post a Comment