42

I set my \textwidth and \textheight in the preamble and would like to change both for some pages. How can this be done? E.g., the following example for \textwidth appears to work for the page number, but not for the text:

\documentclass{article} 
\textwidth=5cm \textheight=5cm
\begin{document}
A \hfill B
\eject \textwidth=10cm
A \hfill B
\end{document}

Output (true to scale):

diabonas
  • 25,784
u17
  • 4,976

2 Answers2

58

You can use \newgeometry and \restoregeometry from the geometry package:

\documentclass{article}
\usepackage[textwidth=5cm,textheight=5cm]{geometry}
\usepackage{lipsum}
\begin{document}

\lipsum[1-2]
\newgeometry{textwidth=10cm,textheight=10cm}
\lipsum[1-4]
\restoregeometry
\lipsum[1-2]

\end{document}
Alan Munn
  • 218,180
Gonzalo Medina
  • 505,128
  • 1
    That's great - thanks. I had given up on the geometry package after it frustrated me in this question: http://tex.stackexchange.com/questions/6834/change-paper-size-in-mid-document – u17 Mar 14 '11 at 22:11
  • 5
    Is there a way to change the text column width mid-page? – cjm Apr 26 '16 at 04:21
  • 1
    Tried this and the text width works fine but the page numbering is no longer centered. Is there a way to fix that? I'm using \fancyfoot[C]{\thepage} from the fancyhdr package. – Kajsa Feb 16 '19 at 17:08
  • @cjm: adjustwidth seems to be useful for that. Note that floats don't get scaled. – tobiasBora Nov 26 '21 at 00:34
10

To change textwidth locally for a defined scope you may use \begin{minipage}{WIDTH}.

\begin{minipage}{10cm}
...
\end{minipage}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • 6
    Welcome, minipages cannot be broken, so the content might overflow the page at the bottom. – Johannes_B Sep 18 '16 at 11:21
  • It's interesting, pages cannot be broken with minipage, but pages must be broken with \newgeometry. It complements the previous one for the cases when the textwidth change takes place at the same page of the unchanged text. – loved.by.Jesus Feb 22 '22 at 14:36
  • This one is perfect for my usage with the TeXMaths plug in for LibreOffice – mikemtnbikes Aug 22 '23 at 18:42