目录 - 将页码放在章节名称后面

目录 - 将页码放在章节名称后面

我想在标准目录中添加页码紧接着章节/节/小节...名称未右对齐。我尝试了tocstyle包,但它会更改目录的其他参数,例如缩进等。

UPD:我使用我们研究所的论文课程,该课程基于report课程,这些是他们做出的与目录相关的定义:

%%% Table of contents

\setcounter{tocdepth}{2}
\renewcommand\@pnumwidth{1.85em}
\def\numberline#1{\ifdim\@tempdima>\z@\hb@xt@\@tempdima{\hfil#1.\ }%
    \else{#1.\ }\fi}
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{0em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
     \global\@nobreaktrue
     \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 0.8em \@plus\p@
    \setlength\@tempdima{0em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\renewcommand*\l@section{\@dottedtocline{1}{0.6em}{2.4em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{2.8em}{3.0em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{4.0em}{1.8em}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{5.4em}{1.9em}}
\renewcommand*\l@subparagraph{\@dottedtocline{5}{7.1em}{2.8em}}

因此我想改变/更新这些定义以保持所有其他参数相同。

答案1

标准 ToC 样式可通过以下方式轻松调整:tocloft。它将常规的节段单元分解X\cftX<type>组件。以下是编号的节段单元的排版伪代码表示:

{\cftXfont {\cftXpresnum SNUM\cftXaftersnum\hfil} \cftXaftersnumb TITLE}%
  {\cftXleader}{\cftXpagefont PAGE}\cftXafterpnum\par

哪里X

  • part对于\parts;
  • chap对于\chapters (如果使用具有章节的类);
  • sec对于\sections;
  • subsec对于\subsections;
  • subsubsec对于\subsubsections;
  • para对于\paragraphs;
  • subpara对于\subparagraphs;
  • ...

下面是一个基于此的最小示例,article它调整了目录以满足您对\sections 和\subsections 的需求。样式相当不言自明。

在此处输入图片描述

\documentclass{article}

\usepackage{lipsum}
\usepackage{tocloft}

% Update \sections in ToC
\renewcommand{\cftsecleader}{~}% Content between section title and page number
\renewcommand{\cftsecafterpnum}{\hfill\mbox{}}% Content after section page number
% Update \subsections in ToC
\renewcommand{\cftsubsecleader}{~}% Content between subsection title and page number
\renewcommand{\cftsubsecafterpnum}{\hfill\mbox{}}% Content after subsection page number


\begin{document}

\tableofcontents

\sloppy% Just for this example

\section{First section}\lipsum[1-10]

\subsection{First subsection}\lipsum[6-15]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Second subsection}\lipsum[16-25]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Third subsection}\lipsum[26-35]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Last subsection}\lipsum[36-45]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\section{Second section}\lipsum[11-20]

\subsection{First subsection}\lipsum[6-15]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Second subsection}\lipsum[16-25]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Third subsection}\lipsum[26-35]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Last subsection}\lipsum[36-45]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\section{Third section}\lipsum[21-30]

\subsection{First subsection}\lipsum[6-15]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Second subsection}\lipsum[16-25]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Third subsection}\lipsum[26-35]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Last subsection}\lipsum[36-45]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\section{Final section}\lipsum[31-40]

\subsection{First subsection}\lipsum[6-15]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Second subsection}\lipsum[16-25]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Third subsection}\lipsum[26-35]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\subsection{Last subsection}\lipsum[36-45]
\subsubsection{First subsubsection}\lipsum[11-20]
\subsubsection{Second subsubection}\lipsum[21-30]
\subsubsection{Third subsubsection}\lipsum[31-40]
\subsubsection{Last subsubsection}\lipsum[41-50]

\end{document}

答案2

这是使用包的建议tocbasic

标准舱

\documentclass{book}
\usepackage{blindtext}

\usepackage{tocbasic}
\DeclareTOCStyleEntry[numwidth=2em,indent=0pt]{tocline}{part}
\usepackage{expl3}
\ExplSyntaxOn
  \clist_map_inline:nn
  {part,chapter,section,subsection,subsubsection,paragraph,subparagraph}
  {\DeclareTOCStyleEntry[
    linefill=\enskip,
    raggedpagenumber,
    pagenumberbox=\mbox
  ]{tocline}{#1}}
\ExplSyntaxOff

\begin{document}
\tableofcontents
\part{Part One}
\Blinddocument
\Blinddocument
\setcounter{page}{4000}% only for the example
\part{Part Two}
\Blinddocument
\Blinddocument
\end{document}

结果:

在此处输入图片描述

KOMA-Script 类

\documentclass{scrbook}% loads package tocbasic
\usepackage{blindtext}% only for dummy text

\RedeclareSectionCommands[%
  toclinefill=\enskip,%
  tocraggedpagenumber,%
  tocpagenumberbox=\mbox
]{part,chapter,section,subsection,subsubsection,paragraph,subparagraph}

\begin{document}
\tableofcontents
\part{Part One}
\Blinddocument
\Blinddocument
\setcounter{page}{4000}% only for the example
\part{Part Two}
\Blinddocument
\Blinddocument
\end{document}

结果:

在此处输入图片描述

相关内容