3

I have a pdflatex document in which I switch paper sizes, just for one page, to display a large image. The page number is purposefully omitted from the larger page. I created macros for performing the switch to the larger size page also for switch back.

The first normal sized page after the image is missing a page number, but subsequent pages seem to work OK. Also, if I don't manually insert a page break with \clearpage, it seems that the page is bottomless and my text goes on and on, invisible beyond the bottom of the page (this isn't demonstrated in the MWE below).

Here is a minimal working example. Any idea what's going on here?

\documentclass{article}
\usepackage{pdflscape}

% Macros for changing paper size
\newcommand{\startPaperSizeB}{%
  \clearpage
  \begingroup
  \setlength{\pdfpagewidth}{11in}
  \setlength{\pdfpageheight}{17in}
  \setlength{\paperwidth}{\pdfpagewidth}
  \setlength{\paperheight}{\pdfpageheight}
  \setlength{\textwidth}{526pt}% This one matters
  \setlength{\textheight}{984pt}% This one matters
  \pagestyle{empty}% No page number
  }

\newcommand{\stopPaperSizeB}{\endgroup \clearpage}% The order of these commands makes no difference

\begin{document}
Some stuff on the first page here.

\startPaperSizeB
\begin{landscape}

Text on second page, intended for large image.

\end{landscape}
\stopPaperSizeB

Why no page number here?

\clearpage

Page numbers start working here, no problem.

\end{document}
3
  • Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit.
    – jub0bs
    Commented Mar 14, 2014 at 20:05
  • 1
    If this is a single page alteration, consider using \thispagestyle{empty}, and/or use the geometry package to switch layouts mid-document (using \newgeometry and \restoregeometry).
    – Werner
    Commented Mar 14, 2014 at 20:13
  • @Werner Thanks for the recommendations, but removing the \pagestyle command (or using \thispagestyle instead) makes no difference. From the geometry package documentation: "\newgeometry is almost similar to \geometry except that \newgeometry ... skips papersize-related options." I did do some experimenting, but couldn't get the papersize to change mid-document using geometry.
    – Kerry
    Commented Mar 14, 2014 at 20:31

1 Answer 1

1

Somehow, your text height parameters are in effect at the wrong time, so that LaTeX believes that the third page is much longer than it is. The page number is there, it's just way below the physical page (as you also observed with the text.) You can fix this by putting the macros inside the landscape environment. In order for the change in page size to take effect, you need to eliminate the \begingroup and \endgroup pair, and take advantage of the group created by the landscape environment instead. However, this results in the text on the large second page being badly placed, unless you also set the \hsize parameter. There are lots of these parameters which interact, which is why doing page layouts manually in LaTeX is difficult. In general, I'd recommend using the geometry package instead, but it doesn't seem that it can handle the case of some pages being a different size, as far as I can tell.

\documentclass{article}
\usepackage{pdflscape}

% Macros for changing paper size
\newcommand{\startPaperSizeB}{%
  \setlength{\pdfpagewidth}{11in}
  \setlength{\pdfpageheight}{17in}
  \setlength{\paperwidth}{\pdfpagewidth}
  \setlength{\paperheight}{\pdfpageheight}
  \setlength{\textwidth}{526pt}% This one matters
  \setlength{\textheight}{984pt}% This one matters
  \setlength{\hsize}{\textheight}
  \pagestyle{empty}% No page number
  }

\newcommand{\stopPaperSizeB}{} 

\begin{document}
Some stuff on the first page here.

\begin{landscape}
\startPaperSizeB

Text on second page, intended for large image.

\stopPaperSizeB
\end{landscape}

Page number here!

\clearpage

Page numbers still working here, no problem.

\end{document}
5
  • Are you sure it's possible to use the geometry package to change papersize mid-document? The package documentation suggests that this is not possible (see description of \newgeometry command on page 4).
    – Kerry
    Commented Mar 14, 2014 at 20:37
  • @Kerry: Perhaps you could change the papersize as you currently do, but use \newgeometry to fix the margins and so forth. When I compile the code in my answer, the page numbers are fine, but the text on the second page is far to the right. Rather than figure out what interactions of all the layout parameters is responsible, I thought using geometry might work. Commented Mar 15, 2014 at 0:19
  • @Kerry: I think you're right, and geometry can't handle different page sizes. I found that the text on the second page is better positioned if you set the \hsize parameter in the macro. I edited the answer. Commented Mar 15, 2014 at 1:00
  • I'm accepting this answer as the solution, since it nicely fixes the MWE in my question. When I went back to implement this fix in my document, however, it turns out thing are different if I'm using a big float on the landscape page. I'll ask another question for this issue, but it will take some time for me to reduce my tex document to a MWE.
    – Kerry
    Commented Mar 16, 2014 at 15:38
  • Your suggestion to use my current method to change papersize and \newgeometry to fix margins turned out to be the winner. The key is to use the \newgeometry BEFORE \begin{landscape} and \restoregeometry AFTER \end{landscape}, but to set the papersize parameters within the landscape environment as you do in your answer above.
    – Kerry
    Commented Mar 17, 2014 at 16:40

You must log in to answer this question.

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