Page LayoutChange Layout Only On The Last Page

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
fmueller
Posts: 1
Joined: Fri Jun 24, 2011 6:29 pm

Change Layout Only On The Last Page

Post by fmueller »

Hi,

I'm trying to change the layout of the last page in a document.

For this I'm using the lastpage, the geometry and the xifthem package.

Code: Select all

\ifthenelse{\thepage=\pageref{LastPage}}{
%Adding new geometry
\newgeometry{bottom=12.5cm}
}{}
The above code checks if we are on the last page of the document and adjusts the bottom margin.

The problem is: this inserts another a second page which is not what I want.

I want this:

- If there is just one page => Bottom margin should be 12.5cm
- If there are multiple pages => Bottom margin should be Xcm except for the last page. There it should be 12.5cm

Full, misbehaving example:

Code: Select all

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{lastpage}
\usepackage{xifthen}
\usepackage[a4paper]{geometry}

\begin{document}

\ifthenelse{\thepage=\pageref{LastPage}}{
\newgeometry{bottom=12.5cm}
}{}

\lipsum

\end{document}
Thanks in advance for any help.

Regards, Florian

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

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Change Layout Only On The Last Page

Post by 5gon12eder »

Section 7 of the geometry documentation states:
Note that both \newgeometry and \restoregeometry insert \clearpage where they are called.
So it will not do the trick you want.

The other problem with your code is that you put an if-condition at the beginning of your document that checks if the current page is the last one. This is equivalent to check if the document is only one page. If it is longer, nothing will happen at all as you observed it.

The simplest solution I can think of is to insert a \vspace{9cm} after the end of your text. (Supposing your regular bottom margin is 3.5 cm.) But I can not guarantee it will work fine under all circumstances.

Best
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
Post Reply