LaTeX forum ⇒ Page LayoutProper way to include a pdf as an appendix Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
javascripter
Posts: 3
Joined: Mon Feb 10, 2020 7:04 pm

Proper way to include a pdf as an appendix

Postby javascripter » Mon Feb 10, 2020 7:10 pm

so, I am including pdfs as an appendix, so far I have been using pdfpages to just include the whole pdf. However, this caused a problem if I use the \chapter{appendix name} method, as the header causes there to be any empty page with no text. I solved this with :

\addcontentsline{toc}{chapter}{\protect Appendix \arabic{appen} \hspace{2mm} Power Node User Manual}
\stepcounter{appen}

which works fine, except the page numbering and appendix numbering is no longer correct. I've gotten some idea of how to do it manually, but the problem i'm stuck on now is that I can't get the page number to be overlayed over the pdf, instead it is always underneath and thus not visible. tried using both fancyhf and eso-pic, at least to the point that they work on an appendix that doesn't have a pdf included.

So how do I overlay the appendix/page numbering over the pdf, or does someone else have a reccomendation for a better way to include an appendix from a pdf

User avatar
Ijon Tichy
Posts: 188
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Mon Feb 10, 2020 7:22 pm

Usually appen is not the counter for the appendices. So all I write here is very speculative.

Why don't you use the addtotoc option of \includepdf? And if you want another page style for the included PDF pages, you may try option pagecommand, e.g., pagecommand={\thispagestyle{plain}}.

If this does not help, please show a Infominimal working example. For the MWE, you can use one of the multi-page PDFs of package mwe instead of your original appendix PDF-file. If not, we would need a download link to be able to reproduce the problem.

javascripter
Posts: 3
Joined: Mon Feb 10, 2020 7:04 pm

Postby javascripter » Mon Feb 10, 2020 8:38 pm

Sorry, I should have explained that appen is a counter I created myself to keep track of appendix numbering

I was unaware I could add things to table of contents that way, but it would also work, I would just have to figure out the formatting to get it in the format that I want



but here is minimum working example showing my problem:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{mwe}
\usepackage{eso-pic}
\usepackage{lastpage}

\begin{document}

\AddToShipoutPictureBG*{%
\AtPageUpperLeft{%
\hspace{\paperwidth}%
\raisebox{-\baselineskip}{%
\makebox[0pt][r]{Appendix x \hspace{15mm}}
}}}%

\AddToShipoutPictureBG*{%
\AtPageUpperLeft{%
\hspace{\paperwidth}%
\raisebox{-\baselineskip-\baselineskip}{%
\makebox[0pt][r]{\thepage \hspace{1mm} (\pageref{LastPage}) \hspace{20mm}}
}}}%

\includepdf[pages=-]{example-image-10x16.pdf}
\includepdf[pages=-]{example-image-a.pdf}

\end{document}


I have used eso-pic, but don't really care how it is achieved. In the result the pdf is over the page numbering, which is the problem I am having. In my use case that part of the pdf is white, and pdf has no numbering by default, so I would like to superimpose correct numbering on it.
A secondary problem is that the second page doesn't have the numbering as well.

example doesn't have toc as that part isn't so important (as i have something that works at least somewhat so far) and I don't want to look up how to do a toc right now, this is the first document I've done in latex and it is from a template that I had to do some fixes to get to work properly.

EDIT: I've seen people put the compiled results here but I can't figure out any way; how do I do that?

User avatar
Ijon Tichy
Posts: 188
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Tue Feb 11, 2020 9:38 am

\AddToShipoutPictureBG* adds output to the background of the next page. So this output is behind the first page of the included PDF. There is also a \AddToShipoutPictureFB* that adds output to the foreground of the next page and \AddToShipoutPictureFB (without the star) would add it so every following page.

But as I already told, you can use option pagecommand to change the page style (header and footer) of the incuded PDF pages. A simple example would be
Code: [Select all] [Expand/Collapse] [Download] (pagecommand-example.tex)
  1. \documentclass{article}
  2. \usepackage{pdfpages}
  3. \usepackage{mwe}
  4.  
  5. \begin{document}
  6.  
  7. \includepdf[pages=-,
  8. pagecommand={},% removed the default \thispagestyle{empty}
  9. ]{example-image-10x16.pdf}
  10. \includepdf[pages=-,
  11. pagecommand={},% removed the default \thispagestyle{empty}
  12. ]{example-image-a.pdf}
  13.  
  14. \end{document}

Now, you can see a simple page number at the center of the bottom of the page.

To move the page number to the top and the right, you can use packages like fancyhdr or scrlayer-scrpage. Here is an example with the last one:
Code: [Select all] [Expand/Collapse] [Download] (scrlayer-scrpage-example.tex)
  1. \documentclass{article}
  2. \usepackage{pdfpages}
  3. \usepackage{lastpage}
  4. \usepackage[markcase=noupper]{scrlayer-scrpage}
  5. \clearscrheadfoot
  6. \renewcommand*{\pagemark}{\usekomafont{pagenumber}\thepage{}/\pageref{LastPage}}
  7. \ohead*{\pagemark}
  8. \setkomafont{pageheadfoot}{}% remove the \slshape from the page header/footer
  9.  
  10. \usepackage{mwe}
  11.  
  12. \begin{document}
  13.  
  14. \includepdf[pages=-,
  15. pagecommand={},% removed the default \thispagestyle{empty}
  16. ]{example-image-10x16.pdf}
  17. \includepdf[pages=-,
  18. pagecommand={},% removed the default \thispagestyle{empty}
  19. ]{example-image-a.pdf}
  20.  
  21. \end{document}


As also told, you can use option addtotoc to generate an entry to the table of contents:
Code: [Select all] [Expand/Collapse] [Download] (addtotoc-example.tex)
  1. \documentclass{article}
  2. \usepackage{pdfpages}
  3. \usepackage{lastpage}
  4. \usepackage[automark,markcase=noupper]{scrlayer-scrpage}
  5. \clearscrheadfoot
  6. \renewcommand*{\pagemark}{\usekomafont{pagenumber}\thepage{}/\pageref{LastPage}}
  7. \ihead{\headmark}% Don't use the star version here!
  8. \ohead*{\pagemark}
  9. \setkomafont{pageheadfoot}{}% remove the \slshape from the page header/footer
  10.  
  11. \usepackage{mwe}
  12.  
  13. %\pagestyle{plain}% Please, try out the difference with this command.
  14.  
  15. \begin{document}
  16. \tableofcontents
  17. \blinddocument
  18. \appendix% Standard LaTeX command to begin the appendix
  19. \renewcommand*{\sectionmark}[1]{\markright{\MakeMarkcase{Appendix \thesection: #1}}}% running heads of appendices with prefix
  20. \includepdf[pages=-,
  21. pagecommand={},% removed the default \thispagestyle{empty}
  22. addtotoc={1,section,1,{10x16-Image},{sec:10x16}}
  23. ]{example-image-10x16.pdf}
  24. \includepdf[pages=-,
  25. pagecommand={},% removed the default \thispagestyle{empty}
  26. addtotoc={1,section,1,{A-Image},{sec:A}}
  27. ]{example-image-a.pdf}
  28. \includepdf[pages=-,
  29. pagecommand={},
  30. addtotoc={1,section,1,{Colored Pages},{sec:colorpages}}
  31. ]{example-image-letter-numbered}
  32.  
  33. \end{document}

BTW: scrlayer-scrpage also allows to move the head towards the top of the page:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage{pdfpages}
  3. \usepackage{lastpage}
  4. \usepackage[markcase=noupper,automark]{scrlayer-scrpage}
  5. \clearscrheadfoot
  6. \renewcommand*{\pagemark}{\usekomafont{pagenumber}\thepage{}/\pageref{LastPage}}
  7. \ihead{\headmark}% dont't use the star-version here!
  8. \ohead*{\pagemark}
  9. \setkomafont{pageheadfoot}{}% remove the \slshape from the page header/footer
  10.  
  11. \usepackage{mwe}
  12.  
  13. \begin{document}
  14. \tableofcontents
  15. \blinddocument
  16. \appendix% Standard LaTeX command to begin the appendix
  17. \renewcommand*{\sectionmark}[1]{\markright{\MakeMarkcase{Appendix \thesection: #1}}}% Add prefix "Appendix" before the number in the running head generation
  18. \ModifyLayer[voffset=\headheight]{scrheadings.head.oneside}% Change vertical position of scrheadings head
  19. \ModifyLayer[voffset=\headheight]{plain.scrheadings.head.oneside}% Change vertical position of corresponding plain head
  20. \includepdf[pages=-,
  21. pagecommand={},% removed the default \thispagestyle{empty}
  22. addtotoc={1,section,1,{10x16-Image},{sec:10x16}}
  23. ]{example-image-10x16.pdf}
  24. \includepdf[pages=-,
  25. pagecommand={},% removed the default \thispagestyle{empty}
  26. addtotoc={1,section,1,{A-Image},{sec:A}}
  27. ]{example-image-a.pdf}
  28. \includepdf[pages=-,
  29. pagecommand={},
  30. addtotoc={1,section,1,{Colored Pages},{sec:colorpages}}
  31. ]{example-image-letter-numbered}
  32.  
  33. \end{document}
You can do similar things with the horizontal position or the width. See the KOMA-Script manual for more information.

javascripter
Posts: 3
Joined: Mon Feb 10, 2020 7:04 pm

Postby javascripter » Tue Feb 11, 2020 10:55 am

thanks, I guess I just didn't know how to use the package I was using, that was easier than expected

I did try using the pagecommand thing, I though you needed some arguments until I saw your example (I couldn't find an example when I googled for it), as it didn't work in my case, I would guess something else in the template I'm using makes it not work, but just changing it from BG* to FG does exactly what I want.

however, addtotoc as an argument for pdfpages (I also couldn't find an example of how to put two optional arguments) works better (though I had to figure out how to get the formatting correctly with it) at linking the toc to the correct place in the document, so I use that one.

only problem now is \lastpage only seems to work for page numbering of last chapter, but it seems possible to get page numbers of any chapter, I just need to figure out how


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 2 guests