0

I have several pdf files available, and now I wish to combine them into 1 file, which I call "attachment bundle". I want to put a table of content at the beginning, showing the starting page of each of the single pdf files in the "attachment bundle". I also wish to add a header, to show the global pages of the "attachment bundle". So far so good.

However, when I tried to include the name of each file (e.g. Curriculum vitae, Personal Statement) in the header using \rightmark, the titles (i.e. section names) do not show up. How to fix this?

Below is my code. Sorry it's a bit messy.

\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{
 headsep=28mm
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset[LO,RE]{20mm}
\fancyheadoffset[RO,LE]{35mm}
\usepackage{lastpage}
\fancyhead[LO,RE]{Attachment bundle, Page \thepage/\pageref{LastPage}}
\fancyhead[RO,LE]{\rightmark}
\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}} 
\addto\captionsUKenglish{% Replace "UKenglish" with the language you use
  \renewcommand{\contentsname}%
    {Attachment list}% Change the title of Contents 
}
\usepackage{pdfpages}
\documentclass[12pt,twoside]{article}
\begin{document}

\includepdf[pagecommand={\section[Curriculum vitae]{}}, scale=1, pages=1]{Sections/2020_04_19_cv.pdf}
\includepdf[pagecommand={}, scale=1, pages=2-]{Sections/2020_04_19_cv.pdf}
 % to avoid an empty page

\includepdf[pagecommand={\section[Personal Statement]{}}, scale=1, pages=1]{Sections/2020_04_19_Personal_Statement.pdf} 
\includepdf[pagecommand={}, scale=1, pages=2-]{Sections/2020_04_19_Personal_Statement.pdf}

\tableofcontents
\end{document}  
fyang
  • 195
  • If you want to interact with the elements of the included PDF, you're probably better off including their corresponding .tex files with \input or \include, assuming they're TeX documents; if they're not, you'll probably have to set these things manually in your main .tex file with e.g. \renewcommand{\rightmark}{something}. – steve May 02 '20 at 19:22
  • I defined \rightmark manually and it worked. Thanks! – fyang May 02 '20 at 19:28

1 Answers1

1

In twoside mode \section sets the left mark not the right one:

\documentclass[12pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{
 headsep=28mm
}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset[LO,RE]{20mm}
\fancyheadoffset[RO,LE]{35mm}
\usepackage{lastpage}
\fancyhead[LO,RE]{Attachment bundle, Page \thepage/\pageref{LastPage}}
\fancyhead[RO,LE]{\leftmark}
\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\begin{document}

\includepdf[pagecommand={\section[Curriculum vitae]{}}, scale=1, pages=1]{example-image}
\includepdf[pagecommand={}, scale=1, pages=2-6]{example-image-duck}
\end{document}  

enter image description here

Ulrike Fischer
  • 327,261