如果紧接在它之前的目录页共享相同的页码,那么 LaTeX 中是否可以有一个不显示特定小节的页码的目录页?
例如,如果同一页上有 3 个小节,那么目录页中是否可以仅在第一行显示页码?
我还以类似以下的方式使用 titletoc 包:
\documentclass{article}
\usepackage{titletoc}
\titlecontents{section}[0pt]{\thecontentspage\quad\thecontentslabel\quad}{}{}{}
\titlecontents{subsection}[0pt]{\thecontentspage\quad\thecontentslabel\quad}{}{}{}
\titlecontents{subsubsection}[0pt]{\thecontentspage\quad\thecontentslabel\quad}{}{}{}
\begin{document}
\tableofcontents
\section{FIRST}
\subsection{FIRST first}
\subsection{FIRST third}
\newpage
\subsubsection{FIRST third b}
\section{SECOND}
\subsection{SECOND first}
\end{document}
它不包含点,并显示节/小节/小小节编号左侧的页码。
答案1
解决方案:使用titletoc
。自注释代码,您必须将代码块后 \usepackage{titletoc}
但前 \begin{document}
。
\documentclass{article}
\usepackage{titletoc}
\titlecontents{section}[0pt]{\thecontentspage \quad \thecontentslabel \quad}{}{}{}
\titlecontents{subsection}[0pt]{\thecontentspage \quad \thecontentslabel \quad}{}{}{}
\titlecontents{subsubsection}[0pt]{\thecontentspage \quad \thecontentslabel \quad}{}{}{}
% START HERE
\makeatletter
\AtBeginDocument{
\g@addto@macro{\tableofcontents}{\let\l@lastnumber\relax}
\let\old@ttl@tocentry\ttl@tocentry
\def\ttl@tocentry#1#2#3#4#5#6#7#8{%
\edef\l@thisnumber{#8}% store current page number
\old@ttl@tocentry{#1}{#2}{#3}{#4}{#5}{#6}{#7}{%
\ifnum\ttl@b>1\relax% the value here determines which levels will ALWAYS have page numbers
\ifx\l@thisnumber\l@lastnumber% if the numbers are the same
\leavevmode\phantom{\l@thisnumber}%
\else% if the numbers differ
\l@thisnumber
\fi
\else% if the level has to have the page number always
\l@thisnumber
\fi}%
\edef\l@lastnumber{#8}% save the page number for the next ToC line
}
}
\makeatother
% END HERE
\begin{document}
\tableofcontents
\listoftables
\section{FIRST}
\subsection{FIRST first}
\subsection{FIRST second}
\subsection{FIRST third}
\subsubsection{FIRST third a}
\newpage
\subsubsection{FIRST third b}
\subsubsection{FIRST third c}
\subsection{FIRST fourth}
\section{SECOND}
\subsection{SECOND first}
\end{document}
答案2
解决方案是使用以下注释良好的脚本。显然,您需要以 开头\makeatletter
和 结尾的部分\makeatother
。
\documentclass{article}
\makeatletter
% replace 'section' by 'chapter' in the 'report' class (on the following 4 lines)
\let\old@l@section\l@section
\def\l@section#1#2{%
\def\l@lastnumber{#2}%
\old@l@section{#1}{#2}% store the page number for section as well
}
\let\old@dottedtocline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\begingroup% we modify \leaders in some cases
\def\l@thisnumber{#5}% store this page number
\ifx\l@thisnumber\l@lastnumber% if the page number is the same...
\let\leaders\@gobbletwo% suppress dots on this line
\let\l@thisnumber\relax% suppress page number on this line
\fi%
\old@dottedtocline{#1}{#2}{#3}{#4}{\l@thisnumber}% the original macro
\endgroup%
\def\l@lastnumber{#5}% store the page number
}
% reset the stored value at the end of the ToC/LoT/LoF
\g@addto@macro{\tableofcontents}{\let\l@lastnumber\relax}
\g@addto@macro{\listoftables}{\let\l@lastnumber\relax}
\g@addto@macro{\listoffigures}{\let\l@lastnumber\relax}
\makeatother
\begin{document}
\tableofcontents
\listoftables
\section{FIRST}
\subsection{FIRST first}
\subsection{FIRST second}
\subsection{FIRST third}
\subsubsection{FIRST third a}
\newpage
\subsubsection{FIRST third b}
\subsubsection{FIRST third c}
\subsection{FIRST fourth}
\section{SECOND}
\subsection{SECOND first}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\begin{table}This is a table.\caption{Table caption}\end{table}
\end{document}