GeneralSpecial margins on certain pages

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
emf2268
Posts: 3
Joined: Thu Oct 23, 2008 8:51 pm

Special margins on certain pages

Post by emf2268 »

I have a document I'm trying to write in Latex. It is generated by a PHP script; the first page may or may not have enough text to move to the next page. Now, the second page forward has a header, and thus a non-zero header height, separation, and top margin. The first page, however, does not have a header and the text is near the top of the page. How can I tell Latex to change the margins once the first page is over?

I tried \afterpage{\headsep 10pt} (or whatever the size is) and other examples of \afterpage, but it does not seem to execute. I can't do a hard page break; I don't know how much content will be on the page since it's generated automatically. Here it my code so far:

Code: Select all

\documentclass[11pt]{article}

\usepackage{afterpage}
\usepackage[strict]{changepage}
\usepackage{ifthen}
\usepackage{endfloat}
\usepackage{lastpage}
\usepackage{amsmath}
\usepackage[left=2cm,top=0cm,right=2cm,bottom=3cm,nohead,nofoot]{geometry}

\usepackage{fancyhdr}
\headheight 0pt
\fancyheadoffset[R]{0in}
\fancyhead[R]{Header}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}

\begin{document}
\afterpage{\setlength{\headheight}{53pt}}
\thispagestyle{plain}
Text!  Insert a lot of lines here to see the effect I'm talking about.

\newpage
\pagebreak[4]
Text!
\newpage
\pagebreak[4]
More text!

\end{document}

Recommended reading 2024:

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

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

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Special margins on certain pages

Post by Juanjo »

The following code may help you:

Code: Select all

\documentclass[11pt]{article}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage[left=2cm,top=3cm,right=2cm,bottom=3cm]{geometry}

\usepackage{fancyhdr}
\fancyhead[R]{Header}
\pagestyle{fancy}

\begin{document}

\thispagestyle{plain}
\vspace*{-3cm}
\afterpage{\vspace*{-3cm}\thispagestyle{plain}}
\lipsum[1-30]

\end{document}
I don't understand which should be the layout of the second page. Has it always a header? Has it a header only if the text in the first page is short? If the answer to the first question is affirmative, you should remove the \afterpage command from the above code.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
emf2268
Posts: 3
Joined: Thu Oct 23, 2008 8:51 pm

Special margins on certain pages

Post by emf2268 »

Every page after the first has a header. It goes like this:

First page:
-No header
-Small top margin

Every other page, even if text from the first page "floats" to the second:
-Header
-Normal top margin

Here's my code now:

Code: Select all

\documentclass[11pt]{article}

\usepackage{afterpage}
\usepackage{ifthen}
\usepackage{endfloat}
\usepackage{lastpage}
\usepackage{amsmath}
\usepackage[left=2cm,top=1cm,right=2cm,bottom=3cm,nohead,nofoot]{geometry}

\usepackage{fancyhdr}
\headheight 0pt
\fancyheadoffset[R]{0in}
\fancyhead[R]{Header}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}

\begin{document}
\vspace*{-1cm}
\afterpage{\vspace*{2cm}}
\thispagestyle{plain}
Title!

\newpage
\pagebreak[4]
Text!
\newpage
\pagebreak[4]
More text!

\end{document}

But as before, afterpage doesn't seem to have any effect.
emf2268
Posts: 3
Joined: Thu Oct 23, 2008 8:51 pm

Re: Special margins on certain pages

Post by emf2268 »

No, wait, nevermind. Got it. It works fine. Thanks for your help! :P
Post Reply