Page LayoutChanging Typearea for the first Page only

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
EmilioLazo
Posts: 15
Joined: Sat Jul 16, 2011 1:59 am

Changing Typearea for the first Page only

Post by EmilioLazo »

Hi!

I'm writing one document with a letterhead which applies only to the first page, so I needs the margins changed, in particular I need to change the \textheight length only for one page of the document: the first.

I have success doing this the "bad" way but I'm trying to do it better (Knuth-compliant way). :)

I'm doing the following (the bad way):

Code: Select all

\usepackage{changepage}
\begin{document}
\changepage{1.5cm}{}{}{}{}{-1.5cm}{}{}{}
.
THE LETTERHEAD CODE (not important here).
.
.
.
Document text
.
.
.
Here comes the bad thing: somewhere the new page happens, so I need to revert the \changepage command almost exactly after the second page begins:
\changepage{-1.5cm}{}{}{}{}{1.5cm}{}{}{}
.
.
.
This works but requires manual intervention to put \changepage at the correct place, or force a new page with \pagebreak before the \changepage command used to restore the margins.

What I want? I want something like making a page style definition and calling it with \thispagestyle after document's begins, i.e.:

Code: Select all

\makeatletter
\def\ps@titlepage{
\changepage{1.5cm}{}{}{}{}{-1.5cm}{}{}{}
}
\makeatother
\begin{document}
\thispagestyle{titlepage}
This solution does not works, this changes the \topmargin adding -1.5cm but ignores the addition of 1.5cm to \textheight. Using \pagestyle{titlepage} does changes both lengths! but this is not what I want, so there is a difference in the implementation of \pagestyle and \thispagestyle.

I did search inside latex.ltx format file and I have found that \thispagestyle command defines \@specialstyle to the arg. of \thispagestyle{} and sets \@specialpagetrue which will be checked inside \@outputpage to define the page style only for the current page, I guess this happens after something that doesn't allows changing \textheight variable.

Also I did test the following:

Code: Select all

\def\ps@titlepage
{
 \addtolength{\textheight}{1.5cm}%
 \addtolength{\topmargin}{-1.5cm}%
 \setlength{\@colht}{\textheight}\setlength{\@colroom}{\textheight}%
 \setlength{\vsize}{\textheight}%
}
(this is without using 'changepage' package), but has the same results, i.e. \textheight not changed using \thispagestyle, and both lengths changed using \pagestyle.

Also, something like \AtBeginNextPage (which doesn't exists) should work the following way:

Code: Select all

\begin{document}
\changepage{1.5cm}{}{}{}{}{-1.5cm}{}{}{}
\AtBeginNextPage{
\changepage{-1.5cm}{}{}{}{}{1.5cm}{}{}{}
}
How can I make \textheight length changed only for one page?

Thanks!!

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

Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Changing Typearea for the first Page only

Post by Stefan Kottwitz »

Hi Emilio,

welcome to the board!

You could use the geometry package. geometry 5.1 and later supports changing page dimensions even in the middle of a document or just for the title page. It offers commands \newgeometry{…} and \restoregeometry for that purpose.

Stefan
LaTeX.org admin
EmilioLazo
Posts: 15
Joined: Sat Jul 16, 2011 1:59 am

Changing Typearea for the first Page only

Post by EmilioLazo »

Hi Stefan,

Thanks!

\newgeometry option has one disadvantage for me: it can't change only one value at its invocation remembering the current page layout, i.e. \newgeometry{vmargin={0.5cm}} sets the top margin to 0.5cm but also sets all other values to to their default, so using \newgeometry requires pasting the \geometry line at preamble with the changed margin. Yes, I'm using geometry package. I forgot to mention it in the first message! But there is no difference without geometry.

Also using \newgeometry that way I have the same behavior. I'll try to paste a minimal code which reproduces that:

Code: Select all

\documentclass[12pt]{article}
\usepackage{changepage}
\usepackage[letterpaper]{geometry}
\geometry{vmargin={2.7cm,2.7cm},hmargin={3.6cm,2.6cm}}
\setlength{\parindent}{0pt}
\makeatletter
\def\ps@test{
\newgeometry{vmargin={0.7cm,2.7cm},hmargin={3.6cm,2.6cm}}
}
\def\ps@testt{
 \changepage{2cm}{}{}{}{}{-2cm}{}{}{}
}
\makeatother
\begin{document}
\thispagestyle{test}
%\thispagestyle{testt}
%\pagestyle{test}
%\pagestyle{testt}
O\hrulefill O
\vfill
O\hrulefill O
\newpage
O\hrulefill O
\vfill
O\hrulefill O
\end{document}
In the code we have two "page styles", one which changes the margins with geometry and one which do the same with changepage. In both of them, when the page style is set with \thispagestyle, the margins are not set correctly (indeed, \textheight), and if we use \pagestyle, everything works fine.

Why I don't want to use \pagestyle? Because I need to put the next \pagestyle at hand when the first page ends and before the first ink drop is written to the second page. :)

Thanks for your answer!

Emilio.
Post Reply