1

I can include pdf documents as they are in the common pdf document, but I cannot do it with common page numbering in the top right corner. The following fancyhdr does not have any effect on have page numbering on the top of pdf documents. It would be great if the page numbering would be on top of pdf documents because they are just articles where plenty of space there. Code proposed based on the thread Base document page numbers with pdfpages about base document

\documentclass{article}
\usepackage{pdfpages}

% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\thepage}

\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border

\begin{document}
\includepdf[pagecommand=\thispagestyle{plain}]{sforzo.pdf}
\includepdf[pagecommand=\thispagestyle{plain}]{testData.pdf}
\includepdf[pagecommand=\thispagestyle{plain}]{sforzo.pdf}
\end{document}

Fig. 1 Output with pagestyle{plain} where you see that the approach decreases the size of the page, Fig. 2 Output with pagestyle{fancy} and renewcommand

enter image description here enter image description here

The fancy pagestyle looks better, but I would still like to maintain the page size. The following Werner's proposal stays in loop and never ends, so I cannot get any output with it

\let\oldincludepdf\includepdf \renewcommand{\includepdf}[2][]{\oldincludepdf[pagecommand=\‌​thispagestyle{fancy}‌​,#1]{#2}}

Werner's correct answer

\usepackage{letltxmacro} \LetLtxMacro\oldincludepdf\includepdf \renewcommand{\includepdf}[2][]{\oldincludepdf[pagecommand={‌​\thispagestyle{fancy‌​}},#1]{#2}}

Output without decreasing the page size

enter image description here

TeXLive 2016
OS: Debian 8.5

  • 1
    Don't use \thispagestyle{plain}; you need \thispagestyle{fancy} for it to match your fancy pages style. – Werner Nov 08 '16 at 07:12
  • 1
    The default under the fancy page style is to have a header rule. To remove this, set \renewcommand{\headrulewidth}{0pt}. – Werner Nov 08 '16 at 07:18
  • 1
    ...also, I don't understand your "keep the page size request". Do you want to keep the page size of the original article, or the one you want to include? – Werner Nov 08 '16 at 07:19
  • 1
    Sure, try: \let\oldincludepdf\includepdf \renewcommand{\includepdf}[2][]{\oldincludepdf[pagecommand=\thispagestyle{fancy},#1]{#2}} – Werner Nov 08 '16 at 07:22
  • 1
    Sorry, use \usepackage{letltxmacro} \LetLtxMacro\oldincludepdf\includepdf \renewcommand{\includepdf}[2][]{\oldincludepdf[pagecommand={\thispagestyle{fancy}},#1]{#2}}. – Werner Nov 08 '16 at 07:33
  • @Werner The question is open, do you want to add an answer? – Johannes_B Nov 13 '16 at 08:37

1 Answers1

3

Add each page with the pagecommand={\thispagestyle{fancy}} option, or "automate" the process via

\usepackage{letltxmacro}
\LetLtxMacro\oldincludepdf\includepdf
\renewcommand{\includepdf}[2][]{%
  \oldincludepdf[pagecommand={‌​\thispagestyle{fancy‌​}},#1]{#2}}
Werner
  • 603,163