여러 PDF를 병합하기 위해 다음 MWE를 사용하고 있습니다. 서로 다른 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)에 페이지 번호가 표시되는 방식을 다시 정의해야 합니다. 다음은 TOC 모양을 사용자 정의하기 위해 tocloft 패키지를 사용하고 사용자 정의 머리글/바닥글을 추가하기 위해 fancyhdr 패키지를 사용하는 최소 작업 예제(MWE)입니다.
\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}