Page LayoutSetting top margin with geometry: Where is my mistake?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
TommyJay
Posts: 4
Joined: Thu Jan 06, 2011 9:03 pm

Setting top margin with geometry: Where is my mistake?

Post by TommyJay »

Hello everyone,
my goal is to simply set the page margins using the geometry package:

here comes my MWE:

Code: Select all

\documentclass[12pt, a4paper, oneside]{scrbook}
\usepackage{geometry}
\geometry{a4paper, top=1.5cm, left=2.5cm, right=3.0cm, bottom=2.0cm}
\begin{document}
\chapter{test}
imagine 2 or 3 pages full of text
...
\end{document}
The left and right margins are correct. However, top and bottom are not correct at all. The page numbers are printed nealry at the bottom of the page. It looks like 0cm space. The chapter headline seems to have a correct top margin, but the second page has no top margin at all... I assume I´ve done a really stupid mistake but i´m not able to see the wood for the trees ... :(. Seriously, i don´t get what i´m doing wrong! I appreciate your help!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Setting top margin with geometry: Where is my mistake?

Post by frabjous »

By default, the top= and bottom= settings set the distance to the actual text, not the distance to the header and footer. The header and footer are put in the margins. If you want to include the header and footer inside what the package considers to be the body of the text, rather than putting the header and footer in the margins, consider using the includehead and includefoot options:

Code: Select all

\geometry{a4paper, top=1.5cm, left=2.5cm, right=3.0cm, bottom=2.0cm, includehead, includefoot}
See the geometry package documentation for a full explanation.
TommyJay
Posts: 4
Joined: Thu Jan 06, 2011 9:03 pm

Re: Setting top margin with geometry: Where is my mistake?

Post by TommyJay »

thx! but when i do that, my header starts at the top of the page (Not after 1.5cm). includefoot seems to work properly, but includehead not. I´m confused ...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Setting top margin with geometry: Where is my mistake?

Post by frabjous »

I can't duplicate your problem. Out of curiousity, how are you compiling? pdflatex? Or latex > dvips > ps2pdf? Or...? Have you checked to make sure the page size is ending up A4 (and not, e.g., letter.)

For me, this code:

Code: Select all

\documentclass[12pt, a4paper, oneside]{scrbook}
\usepackage{geometry}
\geometry{a4paper, top=1.5cm, left=2.5cm, right=3.0cm, bottom=2.0cm, includehead, includefoot}
\usepackage{lipsum}% generates filler text
\begin{document}
\chapter{test}
\lipsum[1-50]% generate 50 filler paragraphs
\end{document}
generates pages that look like:
page.png
page.png (78.21 KiB) Viewed 30139 times
TommyJay
Posts: 4
Joined: Thu Jan 06, 2011 9:03 pm

Re: Setting top margin with geometry: Where is my mistake?

Post by TommyJay »

used exactly your code and compiled with latex > dvips > ps2pdf.
but it doesn´t look like yours :(
i cannot upload a screenshot of my page cause it is too big. How did you make such a nice screen? :)
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Setting top margin with geometry: Where is my mistake?

Post by frabjous »

I just zoomed out in my PDF viewer (MuPDF) before taking the screenshot. I used the import function of ImageMagick to draw which region of the screen I wanted to capture.

Could you upload the resulting PDF from compiling my code here?

I've been using pdflatex, although I get the same results with the dvips / ps2pdf routine. Still, it's very likely we're using different versions.

I'm using:
pdfTeX 3.1415926-1.40.11-2.2 (TeX Live 2010)
dvips(k) 5.99
ps2pdf from Ghostscript 9.00
all on Arch Linux x64_64

I suspect the problem has to do with some step in the conversion process. Check the intermediate dvi and ps files and see if they have the same problem. I know some people have been having trouble with one of these trying to force A4 pages on to letterpaper. Since A4 and letterpaper are about the same sized width, but A4 is taller, this could have the effect of shaving off the top.

If the .dvi is fine, but the .ps is wrong, try calling dvips with the "-t a4" flag. If the .ps is fine, but the .pdf is wring, try calling ps2pdf with the "-sPAPERSIZE=a4" flag.
TommyJay
Posts: 4
Joined: Thu Jan 06, 2011 9:03 pm

Re: Setting top margin with geometry: Where is my mistake?

Post by TommyJay »

my pdf dokument is attached.

Basically I use Miktex 2.7, TexmakerX on Windows XP.
That contains:
dvips(k) 5.96
Miktex GPL Ghostscript 8.60
Miktex PDFlatex 2.7.2808

I figured out that it works fine when i use PDFLatex! So i guess something is wrong with my packages ... Furthermore they are a little outdated. Do you have any recommandations for WinXP and TexmakerX? At work i also use Linux and TexLive.
Attachments
test.pdf
(70.09 KiB) Downloaded 501 times
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Setting top margin with geometry: Where is my mistake?

Post by frabjous »

As I suspected, that PDF uses letter-sized paper rather than A4-sized paper. Did you check the DVI and PS files to see where in the process the problem was creeping in?

Did you try the suggestions I made for flags for dvips or ps2pdf?

You could try upgrading to MikTeX 2.9 and Ghostscript 9.00 and see if that helps, but I don't use Windows, and the advice I'd really like to give ("Don't use Windows. Install Linux instead.") isn't very productive. :D
Post Reply