我想在我的 中获得以下输出table of contents
。如何实现这一点。
我的 MWE 是:
\documentclass{book}
\usepackage{tocloft}
\makeatletter
\renewcommand*{\l@section}[2]{%
\ifnum \c@tocdepth >\z@
\if@cfthaschapter
\vskip \cftbeforesecskip
\else
\addpenalty\@secpenalty
\addvspace{\cftbeforesecskip}
\fi
{\leftskip \cftsecindent\relax
\rightskip \@tocrmarg
\parfillskip -\rightskip
\parindent \cftsecindent\relax\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima \cftsecnumwidth\relax
\let\@cftbsnum \cftsecpresnum
\let\@cftasnum \cftsecaftersnum
\let\@cftasnumb \cftsecaftersnumb
\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
{\cftsecfont #1}\nobreak
\cftsecfillnum{#2}}%
\fi}
\if@cfthaschapter
\setlength{\cftbeforesecskip}{\z@ \@plus.2\p@}
\setlength{\cftsecindent}{2em}
\setlength{\cftsecnumwidth}{2.3em}
\else
\setlength{\cftbeforesecskip}{1.0em \@plus\p@}
\setlength{\cftsecindent}{0em}
\setlength{\cftsecnumwidth}{1.5em}
\fi
\renewcommand*{\l@subsection}[2]{%
\ifnum \c@tocdepth >\@ne
\vskip \cftbeforesubsecskip
{\leftskip \cftsubsecindent\relax
\rightskip \@tocrmarg
\parfillskip -\rightskip
\parindent \cftsubsecindent\relax\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima \cftsubsecnumwidth\relax
\let\@cftbsnum \cftsubsecpresnum
\let\@cftasnum \cftsubsecaftersnum
\let\@cftasnumb \cftsubsecaftersnumb
\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
{\hspace*{-12pt}\cftsubsecfont #1}\nobreak
\cftsubsecfillnum{#2}}%
\fi}
\if@cfthaschapter
\setlength{\cftsubsecindent}{5.5em}
\setlength{\cftsubsecnumwidth}{3.2em}
\else
\setlength{\cftsubsecindent}{1.5em}
\setlength{\cftsubsecnumwidth}{2.3em}
\fi
\parskip .5ex % Add space between Contents items
\makeatother
\begin{document}
\chapter*{Contents}
\markboth{Contents}{Contents}
\contentsline {chapter}{\numberline {6}Decimals}{00}
\contentsline {section}{\numberline {6A}Decimals and place value}{00}
\contentsline {section}{\numberline {6B}Rounding decimals}{00}
\contentsline {section}{\numberline {6C}Addition and subtraction}{00}
\contentsline {section}{\numberline {6D}Multiplying and dividing by powers of 10}{00}
\contentsline {section}{\numberline {6E}Multiplication of decimals}{00}
\contentsline {section}{\numberline {6F}Division of decimals}{00}
\contentsline {section}{\numberline {6G}Decimals and fractions}{00}
\contentsline {section}{\numberline {6H}Decimals and percentages}{00}
\contentsline {subsection}{\numberline {}Investigation}{00}
\contentsline {subsection}{\numberline {}Review: Chapter summary}{00}
\contentsline {subsection}{\numberline {}\qquad Multiple-choice questions}{00}
\contentsline {chapter}{\numberline {}Measurement and Geometry}{}
\contentsline {section}{\numberline {1}Counting}{}
\contentsline {section}{\numberline {2}Numeration}{}
\contentsline {section}{\numberline {6}Fractions}{}
\contentsline {section}{\numberline {7}Calculation}{}
\contentsline {section}{\numberline {8}Number patterns}{}
\contentsline {section}{\numberline {3}Place value}{}
\contentsline {section}{\numberline {4}Addition and subtraction}{}
\contentsline {section}{\numberline {3}Place value}{}
\end{document}
答案1
以下是一些使用 paracol 的实验:
\documentclass{book}
\usepackage[margin=1in]{geometry}
\usepackage{paracol}
\newcommand{\comment}[1]% #1 = text and expandable macros
{\switchcolumn*\vspace{-\baselineskip}#1\switchcolumn}
\newcommand{\commentline}[2]% #1 = text, #2 = \thepage
{\switchcolumn*\vspace{-\baselineskip}#1 \dotfill\makebox[2.25em]{#2}\switchcolumn}
\begin{document}%
\begin{paracol}{2}%
\tableofcontents
\end{paracol}
\chapter{First Chapter}%
\addtocontents{toc}{\string\comment{test 1}}
\section{First Section}
\addtocontents{toc}{\string\commentline{test 2}{\thepage}}
\end{document}