我正在使用以下 MWE 來合併多個 pdf。由於不同的 pdf 都有自己的頁碼,因此我為整個合併文件添加了另一個具有獨特外觀的序列頁碼。例如,我使用了一個黑色邊框和黃色背景的方塊來將新頁碼放在這裡。現在,我希望頁碼的獨特格式也出現在目錄中。我該如何實現這個目標?
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage[includefoot,bottom=3pt]{geometry}
\usepackage[colorlinks=true, linkcolor=blue]{hyperref}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyfoot[C]{\fcolorbox{black}{yellow}{\thepage}}
\usepackage{pdfpages}
\title{Documents for Metric 1.3.1}
\date{}
\begin{document}
\begin{center}
\begin{minipage}{\linewidth}
\begin{center}
\includegraphics[scale=0.3]{Logo.png}\\
\hrulefill
\end{center}
\maketitle
\hrulefill
\end{minipage}
\end{center}
\thispagestyle{empty}
\tableofcontents
\includepdf[pages=-, pagecommand={}, width=\paperwidth, addtotoc={1,section,1,Gender Policy,}]{Gender Policy.pdf}
\includepdf[pages=-, pagecommand={}, width=\paperwidth, addtotoc={1,section,1,Sexual Harassment Redressal Policy,}]{SH.pdf}
\includepdf[pages=-, pagecommand={}, width=\paperwidth, addtotoc={1,section,1,Students' Welfare Policy,}]{SW.pdf}
\includepdf[pages=-, pagecommand={}, width=\paperwidth, addtotoc={1,section,1,Syllabus for Value Education,}]{VE Syllabus.pdf}
\end{document}
答案1
為此,您需要重新定義頁碼在目錄 (TOC) 中的顯示方式。這是一個最小的工作範例 (MWE),使用 tocloft 套件自訂 TOC 外觀,並使用 fancyhdr 套件新增自訂頁首/頁尾。
\documentclass{article}
\usepackage{pdfpages}
\usepackage{xcolor}
\usepackage{tocloft}
\usepackage{fancyhdr}
\usepackage{hyperref}
% Define custom page number style
\newcommand{\mypagenum}[1]{\fcolorbox{black}{yellow}{\textbf{#1}}}
% Redefine the way page numbers are displayed in the TOC
\renewcommand{\cftdotsep}{1.5} % Adjust dot separation
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsecpagefont}{\mypagenum}
% Custom header and footer
\fancypagestyle{plain}{
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\mypagenum{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\begin{document}
\pagestyle{plain}
\tableofcontents
\clearpage
\section{First Section}
\includepdf[pages=-,pagecommand={}]{document1.pdf}
\clearpage
\section{Second Section}
\includepdf[pages=-,pagecommand={}]{document2.pdf}
\clearpage
\section{Third Section}
\includepdf[pages=-,pagecommand={}]{document3.pdf}
\clearpage
\end{document}