# \includepdf and \rightmark do not work with each other?

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{
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\usepackage{lastpage}
\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\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}

• 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}. May 2, 2020 at 19:22
• I defined \rightmark manually and it worked. Thanks! May 2, 2020 at 19:28

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

\documentclass[12pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{
}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}