目次のページ番号のみの外観を変更する方法

目次のページ番号のみの外観を変更する方法

私は次の MWE を使用して複数の PDF を結合しています。異なる PDF にはそれぞれ独自のページ番号が付いているため、結合されたドキュメント全体に別の連続ページ番号を追加して、独特の外観にしています。たとえば、黒い境界線と黄色の背景のボックスを使用して、ここに新しいページ番号を配置しました。ここで、そのページ番号の明確な書式設定を TOC にも表示したいと考えています。どうすれば実現できますか?

\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) でページ番号を表示する方法を再定義する必要があります。以下は、tocloft パッケージを使用して TOC の外観をカスタマイズし、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}

関連情報