Motion Moutain 目录问题

Motion Moutain 目录问题

我有以下代码:

\documentclass[12pt]{article}

\usepackage[cp1250]{inputenc}
\usepackage{lmodern}        % for the looks
\usepackage{biolinum}       % for the looks
\usepackage[T1]{fontenc}

\usepackage{etoolbox}
\usepackage{titletoc}
\usepackage[colorlinks,linktoc=none]{hyperref}


\newcounter{numSubSection}
    \setcounter{numSubSection}{0}

\gpreto{\subsection}{%
    \refstepcounter{numSubSection}}%


\titlecontents{section}[0pt]%
    {\addvspace{6pt}\sffamily\bfseries\normalsize%
        \makebox[18pt][r]{%
            \hyperlink{page.\thecontentspage}{\textbf{\thecontentspage}}%
            \hspace{6pt}}}%
    {\makebox[30pt][r]{\thecontentslabel\hspace{12pt}}}%
    {\makebox[30pt][r]{\null}}%
    {}%


\makeatletter

\newlength{\TOCleftSkip}
    \setlength{\TOCleftSkip}{66pt}%
\newlength{\TOCrightSkip}
    \setlength{\TOCrightSkip}{18pt}%

\newtoggle{ifSub}
    \togglefalse{ifSub}%
\newtoggle{ifSection}
    \toggletrue{ifSection}%
\newcounter{RefSubSection}%
    \setcounter{RefSubSection}{0}%
    \renewcommand*\theRefSubSection{\@arabic\c@RefSubSection}%

\renewcommand*{\tableofcontents}{%
    \section*{\contentsname}%
    \addcontentsline{toc}{section}{\contentsname}%
    \toggletrue{ifSection}%
    \setcounter{RefSubSection}{0}%
    \@starttoc{toc}}%

\gpreto{\l@section}{%
    \nottoggle{ifSection}
        {\par%
            \addtolength{\leftskip}{-\TOCleftSkip}%
            \addtolength{\rightskip}{-\TOCrightSkip}%
            \togglefalse{ifSub}}{}%
    \toggletrue{ifSection}}%

\renewcommand*{\l@subsection}[2]{%
    \stepcounter{RefSubSection}%
    \toggletrue{ifSub}%
    \iftoggle{ifSection}
        {\togglefalse{ifSection}%
            \addtolength{\leftskip}{\TOCleftSkip}%
            \addtolength{\rightskip}{\TOCrightSkip}%
            \noindent}%
        {\unskip\begingroup\upshape\small\ \textbullet~\endgroup}%
    \begingroup%
        \upshape\small#1\ \hyperlink{numSubSection.\theRefSubSection}{\textbf{#2}}%
    \endgroup}%

\renewcommand*{\l@subsubsection}[2]{%
    \iftoggle{ifSection}
        {\togglefalse{ifSection}%
            \addtolength{\leftskip}{\TOCleftSkip}%
            \addtolength{\rightskip}{\TOCrightSkip}%
            \noindent}%
        {\iftoggle{ifSub}
            {\togglefalse{ifSub}\relax%
                \unskip\begingroup\upshape\small:\ \endgroup}%
            {\unskip\begingroup\itshape\small,\ \endgroup}}%
    \begingroup\itshape\small#1\endgroup}%

\renewcommand*{\numberline}[1]{}%

\makeatother


% solution ends here, code below is just for the example
\begin{document}

% Frontmatter - only unnumbered/unlabeled sections
\pagenumbering{roman}
    \clearpage
    \tableofcontents

    \clearpage
    \section*{Preface}
    \addcontentsline{toc}{section}{Preface}

    \clearpage
    \section*{Another Preface}
    \addcontentsline{toc}{section}{Another Preface}


% Mainmatter - only numbered/labeled sections
    \clearpage
    \addtocontents{toc}{\protect\vspace{18pt}}       % just some separation
    \pagenumbering{arabic}
    %\clearpage
    \section{First}
        \subsection{Australia}
            \subsubsection{Alpha}
            \subsubsection{Beta}
            \subsubsection{Charlie}
            \subsubsection{Delta}
            \subsubsection{Echo}
            \subsubsection{Foxtrot}
        \subsection{Brazil}
            \subsubsection{Golf}
            \subsubsection{Hotel}
            \subsubsection{India}
        \subsection{Canada}

    \clearpage
    \section{Second}

    \clearpage
    \section{Third}
        \subsection{Denmark}
            \subsubsection{Juliet}
            \subsubsection{Kilo}
            \subsubsection{Lima}
            \subsubsection{Mike}
            \subsubsection{November}
        \subsection{Egypt}
            \subsubsection{Oscar}
            \subsubsection{Papa}
            \subsubsection{Quebec}
            \subsubsection{Romeo}

    \clearpage
    \section{Fourth}
        \subsection{Georgia}
            \subsubsection{Sierra}
        \subsection{Haiti}
            \subsubsection{Tango}
            \subsubsection{Uniform}
            \subsubsection{Victor}
            \subsubsection{Whiskey}
        \subsection{Iceland}
        \subsection{Japan}
            \subsubsection{X-ray}
            \subsubsection{Yankee}
            \subsubsection{Zulu}
            \subsubsection{Alpha}
            \subsubsection{Beta}
            \subsubsection{Charlie}
            \subsubsection{Delta}
            \subsubsection{Echo}
        \subsection{Kenya}
            \subsubsection{Foxtrot}
        \subsection{Laos}
            \subsubsection{Golf}
            \subsubsection{Hotel}
            \subsubsection{India}
            \subsubsection{Juliet}
            \subsubsection{Kilo}


\end{document}

产生的结果如下:

在此处输入图片描述

如您所见,最后一节的子节和子子节未正确对齐。我该如何更改它?谢谢。

答案1

您需要\par在内容中的最后一个条目后添加一个额外的内容。实现此目的的一种方法是添加

\addtocontents{toc}{\par}

就在之前\end{document}

示例输出

\documentclass[12pt]{article}

\usepackage[cp1250]{inputenc}
\usepackage{lmodern}        % for the looks
\usepackage{biolinum}       % for the looks
\usepackage[T1]{fontenc}

\usepackage{etoolbox}
\usepackage{titletoc}
\usepackage[colorlinks,linktoc=none]{hyperref}


\newcounter{numSubSection}
    \setcounter{numSubSection}{0}

\gpreto{\subsection}{%
    \refstepcounter{numSubSection}}%


\titlecontents{section}[0pt]%
    {\addvspace{6pt}\sffamily\bfseries\normalsize%
        \makebox[18pt][r]{%
            \hyperlink{page.\thecontentspage}{\textbf{\thecontentspage}}%
            \hspace{6pt}}}%
    {\makebox[30pt][r]{\thecontentslabel\hspace{12pt}}}%
    {\makebox[30pt][r]{\null}}%
    {}%


\makeatletter

\newlength{\TOCleftSkip}
    \setlength{\TOCleftSkip}{66pt}%
\newlength{\TOCrightSkip}
    \setlength{\TOCrightSkip}{18pt}%

\newtoggle{ifSub}
    \togglefalse{ifSub}%
\newtoggle{ifSection}
    \toggletrue{ifSection}%
\newcounter{RefSubSection}%
    \setcounter{RefSubSection}{0}%
    \renewcommand*\theRefSubSection{\@arabic\c@RefSubSection}%

\renewcommand*{\tableofcontents}{%
    \section*{\contentsname}%
    \addcontentsline{toc}{section}{\contentsname}%
    \toggletrue{ifSection}%
    \setcounter{RefSubSection}{0}%
    \@starttoc{toc}}%

\gpreto{\l@section}{%
    \nottoggle{ifSection}
        {\par%
            \addtolength{\leftskip}{-\TOCleftSkip}%
            \addtolength{\rightskip}{-\TOCrightSkip}%
            \togglefalse{ifSub}}{}%
    \toggletrue{ifSection}}%

\renewcommand*{\l@subsection}[2]{%
    \stepcounter{RefSubSection}%
    \toggletrue{ifSub}%
    \iftoggle{ifSection}
        {\togglefalse{ifSection}%
            \addtolength{\leftskip}{\TOCleftSkip}%
            \addtolength{\rightskip}{\TOCrightSkip}%
            \noindent}%
        {\unskip\begingroup\upshape\small\ \textbullet~\endgroup}%
    \begingroup%
        \upshape\small#1\ \hyperlink{numSubSection.\theRefSubSection}{\textbf{#2}}%
    \endgroup}%

\renewcommand*{\l@subsubsection}[2]{%
    \iftoggle{ifSection}
        {\togglefalse{ifSection}%
            \addtolength{\leftskip}{\TOCleftSkip}%
            \addtolength{\rightskip}{\TOCrightSkip}%
            \noindent}%
        {\iftoggle{ifSub}
            {\togglefalse{ifSub}\relax%
                \unskip\begingroup\upshape\small:\ \endgroup}%
            {\unskip\begingroup\itshape\small,\ \endgroup}}%
    \begingroup\itshape\small#1\endgroup}%

\renewcommand*{\numberline}[1]{}%

\makeatother


% solution ends here, code below is just for the example
\begin{document}

% Frontmatter - only unnumbered/unlabeled sections
\pagenumbering{roman}
    \clearpage
    \tableofcontents

    \clearpage
    \section*{Preface}
    \addcontentsline{toc}{section}{Preface}

    \clearpage
    \section*{Another Preface}
    \addcontentsline{toc}{section}{Another Preface}


% Mainmatter - only numbered/labeled sections
    \clearpage
    \addtocontents{toc}{\protect\vspace{18pt}}       % just some separation
    \pagenumbering{arabic}
    %\clearpage
    \section{First}
        \subsection{Australia}
            \subsubsection{Alpha}
            \subsubsection{Beta}
            \subsubsection{Charlie}
            \subsubsection{Delta}
            \subsubsection{Echo}
            \subsubsection{Foxtrot}
        \subsection{Brazil}
            \subsubsection{Golf}
            \subsubsection{Hotel}
            \subsubsection{India}
        \subsection{Canada}

    \clearpage
    \section{Second}

    \clearpage
    \section{Third}
        \subsection{Denmark}
            \subsubsection{Juliet}
            \subsubsection{Kilo}
            \subsubsection{Lima}
            \subsubsection{Mike}
            \subsubsection{November}
        \subsection{Egypt}
            \subsubsection{Oscar}
            \subsubsection{Papa}
            \subsubsection{Quebec}
            \subsubsection{Romeo}

    \clearpage
    \section{Fourth}
        \subsection{Georgia}
            \subsubsection{Sierra}
        \subsection{Haiti}
            \subsubsection{Tango}
            \subsubsection{Uniform}
            \subsubsection{Victor}
            \subsubsection{Whiskey}
        \subsection{Iceland}
        \subsection{Japan}
            \subsubsection{X-ray}
            \subsubsection{Yankee}
            \subsubsection{Zulu}
            \subsubsection{Alpha}
            \subsubsection{Beta}
            \subsubsection{Charlie}
            \subsubsection{Delta}
            \subsubsection{Echo}
        \subsection{Kenya}
            \subsubsection{Foxtrot}
        \subsection{Laos}
            \subsubsection{Golf}
            \subsubsection{Hotel}
            \subsubsection{India}
            \subsubsection{Juliet}
            \subsubsection{Kilo}

\addtocontents{toc}{\par}
\end{document}

或者,您可以修改文件\contentsfinish中的最后一个命令.toc

相关内容