138

I have a Latex document where I need to change the margins of only a few pages (the pages where I'm adding a lot of graphics).

In particular, I'd like to change the top margins (\voffset). I've tried doing:

\addtolength{\voffset}{-4cm}

% Insert images here

\addtolength{\voffset}{4cm}

but it didn't work. I've seen references to the geometry package, but I haven't found how to use it for a bunch of pages, and not for the whole document.

Any hints?

pgb
  • 24,813
  • 12
  • 83
  • 113

10 Answers10

222

Use the "geometry" package and write \newgeometry{left=3cm,bottom=0.1cm} where you want to change your margins. When you want to reset your margins, you write \restoregeometry.

Kevin Chen
  • 4,278
  • 3
  • 15
  • 9
  • 9
    Thank you this works perfectly. I found it helped to look at the documentation because there are a lot of other margin options besides just left, right, top and bottom: https://www.sharelatex.com/learn/Page_size_and_margins – Noah Sussman Apr 01 '17 at 17:16
  • 6
    The only problem with `geometry` commands is that they flush the text into the next page if is used in the middle of a page, since the geometry is defined for "page". – Emadpres Oct 27 '19 at 19:01
  • 3
    @Emadpres Since you want to define new margins for some pages, `\newpage` or `\pagebreak` are necessary and natural commands you use first. – C.K. Jul 24 '20 at 06:32
  • If I attempt to use \geometry lyx says "undefined control sequence" how do I install geometry package? Edit: All one needs to do is to insert \usepackage{geometry} into the document preamble like a latter answer specifies. – Miika Vuorio Sep 07 '21 at 17:08
  • @MiikaVuorio, did you solve this problem? It seemed that it is necessary to update the geometry package to version 5, but it didn't solve it for me? – Thibaud Hulin Dec 26 '21 at 13:49
82

I've used this in beamer, but not for general documents, but it looks like that's what the original hint suggests

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

Then to use it

\begin{changemargin}{-1cm}{-1cm}

don't forget to

\end{changemargin}

at the end of the page

I got this from Changing margins “on the fly” in the TeX FAQ.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
ansate
  • 1,321
  • 9
  • 9
  • 8
    This works better for me than using geometry, since including the geometry package in the preamble already breaks the layout of the style I am required to use. – mak Feb 15 '18 at 13:35
  • Works for text for images see below on https://stackoverflow.com/questions/1670463/latex-change-margins-of-only-a-few-pages/1670586#1670586 answer – partizanos Feb 04 '21 at 17:13
  • it looks like this only changes the left and right margins, not the top. what do each of the parameters correspond to?... – Quantum Guy 123 Jun 16 '22 at 18:38
30

I was struggling a lot with different solutions including \vspace{-Xmm} on the top and bottom of the page and dealing with warnings and errors. Finally I found this answer:

You can change the margins of just one or more pages and then restore it to its default:

\usepackage{geometry}
...
... 
...
\newgeometry{top=5mm, bottom=10mm}     % use whatever margins you want for left, right, top and bottom.
...
... %<The contents of enlarged page(s)>
...    
\restoregeometry     %so it does not affect the rest of the pages.
...
... 
...

PS:

1- This can also fix the following warning:

LaTeX Warning: Float too large for page by ...pt on input line ...

2- For more detailed answer look at this.

3- I just found that this is more elaboration on Kevin Chen's answer.

Alisa
  • 2,892
  • 3
  • 31
  • 44
7
\par\vfill\break % Break Last Page

\advance\vsize by 8cm % Advance page height
\advance\voffset by -4cm % Shift top margin
% Start big page
Some pictures
% End big page
\par\vfill\break % Break the page with different margins

\advance\vsize by -8cm % Return old margings and page height
\advance\voffset by 4cm % Return old margings and page height
Alexey Malistov
  • 26,407
  • 13
  • 68
  • 88
4

For figures you can use the method described here :
http://texblog.net/latex-archive/layout/centering-figure-table/
namely, do something like this:

\begin{figure}[h]
\makebox[\textwidth]{%
        \includegraphics[width=1.5\linewidth]{bla.png}
    }
\end{figure}

Notice that if you have subfigures in the figure, you'll probably want to enter into paragraph mode inside the box, like so:

\begin{figure}[h]
\makebox[\textwidth]{\parbox{1.5\textwidth}{ %
\centering
\subfigure[]{\includegraphics[width=0.7\textwidth]{a.png}}
\subfigure[]{\includegraphics[width=0.7\textwidth]{b.png}}
\end{figure}

For allowing the figure to be centered in the page, protruding into both margins rather than only the right margin.
This usually does the trick for images. Notice that with this method, the caption of the image will still be in the delimited by the normal margins of the page (which is a good thing).

shoosh
  • 76,898
  • 55
  • 205
  • 325
2

A slight modification of this to change the \voffset works for me:

\newenvironment{changemargin}[1]{
  \begin{list}{}{
    \setlength{\voffset}{#1}
  }
  \item[]}{\end{list}}

And then put your figures in a \begin{changemargin}{-1cm}...\end{changemargin} environment.

Noah
  • 21,451
  • 8
  • 63
  • 71
1

Look up \enlargethispage in some LaTeX reference.

None
  • 11
  • 1
1

I could not find a easy way to set the margin for a single page.

My solution was to use vspace with the number of centimeters of empty space I wanted:

 \vspace*{5cm}                                                             

I put this command at the beginning of the pages that I wanted to have +5cm of margin.

Neaţu Ovidiu Gabriel
  • 833
  • 3
  • 10
  • 20
1

This worked for me:

\newpage % larger page1
\enlargethispage{1.5cm} % more room for text or floats
\advance\voffset by -0.5cm % reduce top margin
\advance\footskip by 1cm % lower page number
    
Some content

\newpage % larger page2
\enlargethispage{1.5cm}
    
Some content

...

\newpage % return to normal page
\advance\voffset by 0.5cm
\advance\footskip by -1cm
CptHwK
  • 115
  • 1
  • 4
0

I had the same problem in a beamer presentation. For me worked using the columns environment:

\begin{frame}
  \begin{columns}
    \column{1.2\textwidth}
    \begin{figure}
      \subfigure{\includegraphics[width=.49\textwidth]{1.png}}
      \subfigure{\includegraphics[width=.49\textwidth]{2.png}}
    \end{figure}
   \end{columns}
\end{frame}