60

I want to change the geometry for a single page only. I set the geometry for the whole document using:

\usepackage[left=1cm,right=2cm,vmargin=2.5cm,footnotesep=0.5cm]{geometry}

The geometry package provides the commands \newgeometry and \restoregeometry; however, the \newgeometry instruction forces a \clearpage. I just want to change the geometry for one page only, is that possible?


(Addendum applied by @JPi, 15 October 2017:)

The original question apparently didn't make sufficiently clear what the OP intended to achieve, and the (now-deleted) answer appears to correspond to a rather narrow interpretation of the question. I have added an MWE that has the special feature that the page with the different geometry is page 1. But a general solution to this question is sought.

Here is an example of a situation in which this would be useful; there are surely others.

\documentclass[12pt]{letter}

\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{eso-pic}
\usepackage{lipsum}
\usepackage{afterpage}

\newcommand\BackgroundPicture{%
    \put(0,0){%
        \parbox[b][\paperheight]{\paperwidth}{%
            \vfill
            \centering
            \includegraphics[width=\paperwidth,height=\paperheight,%
            keepaspectratio]{letterhead.pdf}%
            \vfill
}}}


\begin{document}

\signature{Me}

\begin{letter}{You}
    \AddToShipoutPicture*{\BackgroundPicture}
%\vspace*{1.25in}  % sure this, works, but it's nasty

\newgeometry{margin=1in,top=3in}
\afterpage{\restoregeometry}

    \opening{Dear Sir/Madam,}

\lipsum

\closing{Yours mournfully,}

\end{letter}

\end{document}

(Another example added by @thymaro on 19 October 2017)

tl;dr Can you specify page geometries before the content is typeset on the pages?

Let's say I have a more or less 11 page document with, in it's preamble

\usepackage[whatever-paper-geometry,margin=2cm]{geometry}  %  keep it simple

I want page 3 of my document to have margins set to 10cm (that will be a vertically very narrow box of text) and I really couldn't care less what the text on that page is. As page 3 now contains almost no text any more, the document will be forced to extend to more or less 12 pages.

Can I (you? anyone?) define page geometry of page [1-2, 3, rest of the document*] in the preamble and then let the text flow into these receptacles?

  • "rest of the document" could really first be defined as page 4-20, and after compilation, see that there are only 12 pages and go back to define "rest of the document" as pages 4-12.

I hope this example does the original question justice.

13
  • 1
    Try the package afterpage.
    – agodemar
    Commented Oct 19, 2012 at 7:26
  • 1
    That doesn't seem to work at all. When I put \afterpage{\restoregeometry} in the document, the geometry is not restored at all.
    – Andre
    Commented Oct 19, 2012 at 7:40
  • 1
    Is the difference only in the layout? Or does it include a difference in the page size as well? Are you working in twoside or not (doesn't seem like it)? Out of curiosity: What is on the page that requires it to have a different geometry? Do you have non-standard elements on that different page? What would you want the new geometry to look like? Do you have any restrictions in terms of the packages used? Would you be able to create a minimal working example (MWE) so we have something to work with that also answers the above questions?
    – Werner
    Commented Oct 19, 2012 at 15:12
  • 6
    I’m voting to reopen this question because I think that, contrary to what has been said, it concerns an issue of general interest. Maybe some day someone will come up with a good solution.
    – GuM
    Commented Jun 15, 2016 at 23:14
  • 2
    @JPi and other editors: Please have a look into "When is it Kosher to edit one’s own question?" Often it is better to ask a new question or a follow-up question instead of do substantial changes to an old question. Commented Oct 19, 2017 at 6:42

2 Answers 2

30

Comment, 15 Oct 2017: The answer given below attempted to address the query as it was phrased originally, i.e., back in October 2012. I’m afraid the answer is not going to be of much interest to the query in its current (Oct. 2017) form.


With help from the afterpage package, the following should work for you:

% ... some material
\afterpage{%
\newgeometry{<options>}
% material for this page
\clearpage
\restoregeometry
} % end of \afterpage{...} material
% ... still more material
5
  • 8
    My problem is that I want LaTeX to decide what to put on the page (in my case there is lots of text). If I woul'd knew what to put on the page then the \restoregeometry would be just fine. I wan't to tell LaTeX: This page has a different geometry, deal with it.
    – Andre
    Commented Oct 19, 2012 at 8:33
  • 1
    If I got it right, you want a new geometry on only one page and you don't know what goes in that page? What is the purpose of that? And of course \newgeometry forces \clearpage, logically you can't have two layouts (margins, page size) on the same page, so layout pages have to go to the next page.
    – user9424
    Commented Nov 18, 2012 at 11:54
  • 2
    The order at the end is important. For some reason we need \restoregeometry\clearpage. Otherwise the bottom margin on the next page is incorrect and text runs into the the end of the page (see tex.stackexchange.com/questions/139834/…)
    – Jörg
    Commented Nov 28, 2014 at 11:34
  • @Joseph well, perhaps one is writing a letter and has a letterhead on page 1. I address that using \vspace, but it's clunky.
    – JPi
    Commented Oct 14, 2017 at 23:38
  • 2
    Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    Commented Oct 19, 2017 at 7:57
1

"Page geometry" can refer to multiple things: the page size, or the page margin.

Even concerning changing only the page margin, it matters if it's the top/bottom margin, or the left/right margin. (Some internal implementation detail of TeX makes one case more difficult than the other.)

It also matters whether you know exactly where is the page boundary.

Changing the paper size mid-document

If you know exactly the page boundary

Refer to Change paper size in mid-document . This requires the typearea package, and it does require you to know what's the content to be put on that page.

If you know what's the content to be put on that page (e.g. a figure), but don't know exactly the page boundary

Refer to Single A3 pages in a A4 document or one of the linked questions Insert A3 page with figure into A4 document with active references Insert foldable A3 pages in an A4 document with active references A3 pages within A4 doc (If someone can tell what's the difference between the solutions please clean up the questions thanks)

If you don't know (and want to specify a particular page number whose size is different)

Quoting egreg:

A paragraph can't use two page geometries, because it's typeset before page breaks are considered.

As far as I can see, there is no limitation why it cannot be implemented, except that the algorithm TeX uses internally makes this impossible. (Maybe it is possible with enough \unhbox and Lua traversal of nodes, I don't know.)

Changing the margin etc. mid-document

If you know exactly the page boundary

This is the easiest case. Refer to geometry package - setting margins on a specific page.

If you know what's the content to be put on that page (e.g. a figure), but don't know exactly the page boundary

Refer to Mico's answer above.

If you don't know, but the left/right margin does not change

Special case: changing the head height for first page

This is also a simple case. Use \vspace at the very beginning of the document. Refer to Different headheight for first page .

More general case

Refer to the answer in Change Geometry after first page *without* knowing where the second page begins .

There is also another answer in https://tex.stackexchange.com/a/425349/250119 but I can't analyze it yet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .