[Tex/LaTex] Page number missing from page following paper size change in pdflatex

landscapepage-numbering

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}

Best Answer

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}