currently I'm trying to prepare a letter head with XeLaTeX. The first page of the letter should have a sidebar on the right. For this sidebar, the text width should be shrinked to approx. 80% of its normal size, so that text won't go into the sidebar. For the following pages, the text width should be normal, i.e. without any additional margins.
I realized that changing the page layout in LaTeX mid-document isn't a trivial task and there exist some solutions, for example, the \newgeometry
command within the geometry
package.
One of my first ideas was to use the atbegshi
package in conjunction with the geometry
package in order to achieve the desired layout change after the first page:
\documentclass{article}
\usepackage{atbegshi}
\usepackage{geometry}
\usepackage{lipsum} % just to have dummy texts
% define the main page layout
\geometry{a4paper, includeall, left=10mm, right=10mm, top=10mm, bottom=10mm, head=0mm, foot=0mm, marginpar=0mm, marginparsep=0mm, headsep=0mm}
% restore the main page layout for all following pages
\AtBeginShipoutNext{\restoregeometry}
\begin{document}
% define a new page layout for the first page
\newgeometry{left=10mm, right=50mm, top=10mm, bottom=10mm, head=0mm, foot=0mm, marginpar=0mm, marginparsep=0mm, headsep=0mm}
\lipsum[1-30]
\clearpage
\lipsum[31-50]
\end{document}
Unfortunately, this won't work. It seems that every atbegshi
hook (\AtBeginShipout
, \AtBeginShipoutFirst
, \AtBeginShipoutNext
) ignores \newgeometry
and \restoregeometry
commands.
I tried several other methods, but this one seems the most sophisticated one, since it would give a very clean way for changing the page layout just for the first page (for example, consider the following MWE; not working for some reason):
\documentclass{article}
\usepackage{atbegshi}
\usepackage{geometry}
\usepackage{lipsum} % just to have dummy texts
% define the main page layout
\geometry{a4paper, includeall, left=10mm, right=10mm, top=10mm, bottom=10mm, head=0mm, foot=0mm, marginpar=0mm, marginparsep=0mm, headsep=0mm}
% define the first page layout
\AtBeginShipoutFirst{\newgeometry{left=10mm, right=50mm, top=10mm, bottom=10mm, head=0mm, foot=0mm, marginpar=0mm, marginparsep=0mm, headsep=0mm}}
% restore the main page layout for all following pages
\AtBeginShipoutNext{\restoregeometry}
\begin{document}
\lipsum[1-30]
\clearpage
\lipsum[31-50]
\end{document}
Does there exist another way of achieving the desired result? Or is it just a bug I encountered with atbegshi
/geometry
?
Note:
Because I neither know the text to be placed at the first page nor its length, the \restoregeometry
command can't be placed manually.
\AtBeginShipoutNext{\restoregeometry}
-- even not after a page break.