15

I am using pdfpages to insert PDFs into a master file. Some of the PDFs are portrait and some are landscape. I am using pagecommand=\thispagestyle{plain} so that the page numbers are in sequence throughout the final document. However, on PDFs included as landscape, the page numbers appear on the left side of the page (i.e. as they would if the page were not landscape). How can I get them to appear on the bottom of the page?

MWE where one.pdf is included in portrait and two.pdf is included in landscape:

\documentclass[12pt,english]{article}
\usepackage{pdfpages}
\includepdfset{pagecommand=\thispagestyle{plain}}
\usepackage{geometry}

\begin{document}

This is the text in the master file.

\newpage{}

\includepdf[pages=-,landscape=false]{one}

\newpage{}

\includepdf[pages=-,landscape=true]{two}

\end{document}
Werner
  • 603,163
user21155
  • 445

1 Answers1

17

Using fancyhdr you can define your own page style and move the page number/counter into the appropriate position.

\usepackage{pdfpages}% http://ctan.org/pkg/pdfpages
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{mylandscape}{%
  \fancyhf{}% Clear header/footer
  \fancyfoot{% Footer
    \makebox[\textwidth][r]{% Right
      \rlap{\hspace{\footskip}% Push out of margin by \footskip
        \smash{% Remove vertical height
          \raisebox{\dimexpr.5\baselineskip+\footskip+.5\textheight}{% Raise vertically
            \rotatebox{90}{\thepage}}}}}}% Rotate counter-clockwise
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}

You would then use pagecommand=\thispagestyle{mylandscape}. Example output with one.pdf (1 page portrait) and two.pdf (1 page landscape):

enter image description here

two.tex:

\documentclass{article}
\usepackage{pdflscape,lipsum}% http://ctan.org/pkg/lipsum
\pagestyle{empty}
\begin{document}
\begin{landscape}
\lipsum[1-5]
\end{landscape}
\end{document}

one.tex:

\documentclass{article}
\usepackage{lipsum,pdfpages,fancyhdr}% http://ctan.org/pkg/{lipsum,pdfpages,fancyhdr}
\fancypagestyle{mylandscape}{%
  \fancyhf{}% Clear header/footer
  \fancyfoot{% Footer
    \makebox[\textwidth][r]{% Right
      \rlap{\hspace{\footskip}% Push out of margin by \footskip
        \smash{% Remove vertical height
          \raisebox{\dimexpr.5\baselineskip+\footskip+.5\textheight}{% Raise vertically
            \rotatebox{90}{\thepage}}}}}}% Rotate counter-clockwise
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}
\begin{document}
\lipsum[1-5]
\includepdf[noautoscale,landscape,pagecommand=\thispagestyle{mylandscape}]{two.pdf}
\end{document}
Werner
  • 603,163
  • This solution isn't working for me. Could you show us how the mylandscape command was included on the page? I am using pdflscape package and begin/end{landscape} to rotate my pages. The solution you have proposed places the page number in bold towards left of the page, not center. – cryptic0 Apr 17 '13 at 23:52
  • @cryptic0: I've added the MWE that creates the image in the answer. – Werner Apr 18 '13 at 02:37
  • Thank you for a quick response and the code. What is the function of two.pdf? – cryptic0 Apr 18 '13 at 02:41
  • @cryptic0: The OP mentioned a separate document which was set in landscape format. In my case, I created a dummy document two.tex which, when compiled with pdflatex, creates two.pdf. – Werner Apr 18 '13 at 02:44
  • What if I didn't want that. Could I then just use \thispagestyle{mylandscape}? – cryptic0 Apr 18 '13 at 02:55
  • @cryptic0 It seems to work for me just using it in a single document setting. – David Doria Jul 02 '14 at 20:09
  • works great, the part with the % Raise vertical comment actually controls the location on the bottom of the landscape page. I needed a quite specific location and used \raisebox{\dimexpr.5\baselineskip+\footskip+.65\textheight – Martin Oct 19 '22 at 18:38