我在创建图书目录时遇到了问题。我想在某些页面的页码后面添加圆括号。但是,当我创建目录时,TOC 中只有页码,没有圆括号。
这是我的示例代码。
\documentclass{article}
\usepackage{amsthm}
% Layout packages
\RequirePackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{calc}
\RequirePackage{indentfirst}
\RequirePackage{titlesec}
\RequirePackage{titletoc}
\newcommand{\setpageWithbracket}{%
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\lhead{} \chead{(\thepage)} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
%\fancyhead[CE,CO]{(\thepage)} % option for twoside
\pagenumbering{arabic}
}%
\newcommand{\setnormalPage}{%
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\lhead{} \chead{\thepage} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\pagenumbering{arabic}
}%
\begin{document}
\setpageWithbracket
\tableofcontents
\newpage
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\newpage
\setnormalPage
\section{Introduction}
This is the first section.
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...
\newpage
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\end{document}
这是我的预期输出。
我的英语水平很差,请大家帮我出出主意。
答案1
由于您的页面样式非常相似(除了 周围的括号外)\thepage
,我建议只设置一种页面样式,并重新定义页码的设置方式 - 为目录和未编号部分添加括号,然后为文档的其余部分重置它。
\documentclass{article}
\usepackage{amsthm}
% Layout packages
\RequirePackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{titlesec}
\RequirePackage{titletoc}
% Use a single page style
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\lhead{} \chead{\thepage} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\begin{document}
\renewcommand{\thepage}{(\arabic{page})}% Put page numbers in parentheses
\tableofcontents
\clearpage
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\clearpage
\pagenumbering{arabic}% Reset page number and set it without parentheses
\section{Introduction}
This is the first section.
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...
\clearpage
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\end{document}
答案2
您需要改变宏的结果\thepage
。
% pagenumprob.tex SE 593029
\documentclass{article}
\usepackage{amsthm}
% Layout packages
\RequirePackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{calc}
\RequirePackage{indentfirst}
\RequirePackage{titlesec}
\RequirePackage{titletoc}
%%% change the page number appearance
\let\savethepage\thepage
\newcommand{\parenpage}{\renewcommand{\thepage}{(\savethepage)}}
\newcommand{\noparenpage}{\renewcommand{\thepage}{\savethepage}}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\lhead{} \chead{\thepage} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\begin{document}
\parenpage
\tableofcontents
\newpage
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\newpage
\noparenpage
\section{Introduction}
This is the first section.
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...
\newpage
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\newpage
\parenpage
\section{Third}
\newpage
\noparenpage
\section{Fourth}
\end{document}