6

Using the following minimal working example

\documentclass[12pt,a4paper]{article}

\usepackage[showframe]{geometry}
\geometry{hmargin={3.5cm,2.5cm}}

\AtBeginDocument{\geometry{vmargin={12cm,5cm}}}

\usepackage{lipsum}

\begin{document}
\lipsum[1-10]
\end{document}

Text on the first page overflows the lower margin. Other pages are fine, as illustrated by the figures below:

  • first page margin (overflown)

First page lower margin overflown

  • other pages (as expected)

Other pages are behaving correctly

I need to use commands in MWE for a complicated sequence (creating a complex template as a document class, calculating some lenghts involved in the template, then putting appropriate margins on the text block to fit into the template), so redefining MWE as an answer is probably not desirable.

2
  • Your title doesn't seem very clear to me. How would you like "Margin overflow when setting the geometry AtBeginDocument"? Mar 9, 2011 at 15:04
  • You are right. And fancyhdr is not necessary either, so I will remove it from the question.
    – ipavlic
    Mar 9, 2011 at 15:10

1 Answer 1

7

You cannot use \geometry for a setting inside the text body. Use \newgeometry instead. However, fancyhdr should always be loaded after geometry.

\documentclass[12pt,a4paper]{article}

\usepackage[showframe]{geometry}
\geometry{hmargin={3.5cm,2.5cm}}

\AtBeginDocument{\newgeometry{vmargin={12cm,5cm}}}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

\usepackage{lipsum}

\begin{document}
\lipsum[1-10]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .