有人可以帮助我根据我将要提供的 MWE 代码调整我的 TOC 吗?
我正在尝试在标题和页码之间添加点。
第 2.1 节、第 3 章和第 3.1.1 小节的标题太长,以至于页码显示在第二行。我需要做什么才能使页码在第二行右对齐并用点连接。
我试图改变的最后一件事是,我希望 3.1.2 和 3.2 之间的空间与 3.1 和 3.1.1 相同
\documentclass[12pt]{book}
\usepackage{etoc}
\usepackage{textcase}
\etocsetlevel{section}{1}
\etocsetlevel{subsection}{2}
\etocsettocdepth{subsection}
\newlength{\tocleft}
\setlength{\tocleft}{2.5cm} % adjust to fit the inner margin defined in geometry
\newlength{\tocsep}
\setlength{\tocsep}{2em}
\etocsetstyle{chapter}
{}
{}
{\etocifnumbered
{\makebox[0pt][r]{\textbf{\etocnumber}\hspace{\tocsep}}%
\textbf{\etocname}\hfill\etocpage\par}
{\textbf{\etocname}\hfill\etocpage}%
\par\vspace{3ex}}
{}
\etocsetstyle{section}
{\vspace{-2ex}}
{}
{\makebox[0pt][r]{\etocnumber\hspace{\tocsep}}%
\etocname\hfill\etocpage\par}
{\addvspace{3ex}}
\etocsetstyle{subsection}
{\vspace{0ex}}
{}
{\makebox[0pt][r]{\etocnumber\hspace{\tocsep}}%
\etocname\hfill\etocpage\par}
{\addvspace{2ex}}
\etocsettocstyle{\chapter*{\contentsname}
\thispagestyle{plain}%
\leftskip\tocleft\parindent0pt}
\begin{document}
\tableofcontents
\chapter{test}
\section{test}
\subsection{test}
\chapter{test}
\section{very long titleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee}
\subsection{test}
\chapter{very long titleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee}
\section{test}
\subsection{very long titleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee}
\subsection{test}
\section{test}
\subsection{test}
\end{document}
非常感谢。
答案1
我用来\allowbreak\mbox{}\nobreak\dotfill
代替\hfill
。
根据垂直空间,我用完全不同的东西替换了原始代码,仅为第一部分(仅)和非第一章添加空间。
(我还修改了一些标题以使其更加真实)
\documentclass[12pt]{book}
\usepackage{etoc}
\usepackage{textcase}
% this is already default so is unneeded
%\etocsetlevel{section}{1}
%\etocsetlevel{subsection}{2}
\etocsettocdepth{subsection}
\newlength{\tocleft}
\setlength{\tocleft}{2.5cm} % adjust to fit the inner margin defined in geometry
\newlength{\tocsep}
\setlength{\tocsep}{2em}
\etocsetstyle{chapter}
{}
{\etociffirst{}{\vspace{3ex}}}
{\etocifnumbered
{\makebox[0pt][r]{\textbf{\etocnumber}\hspace{\tocsep}}%
\textbf{\etocname}\allowbreak\mbox{}\nobreak\dotfill\etocpage\par}
{\textbf{\etocname}\allowbreak\mbox{}\nobreak\dotfill\etocpage}%
\par
}
{}
\etocsetstyle{section}
{}
{\etociffirst{\vspace{1ex}}{}}
{\makebox[0pt][r]{\etocnumber\hspace{\tocsep}}%
\etocname\allowbreak\mbox{}\nobreak\dotfill\etocpage\par}
{}
\etocsetstyle{subsection}
{}
{}
{\makebox[0pt][r]{\etocnumber\hspace{\tocsep}}%
\etocname\allowbreak\mbox{}\nobreak\dotfill\etocpage\par}
{}
\etocsettocstyle{\chapter*{\contentsname}
\thispagestyle{plain}%
\leftskip\tocleft\parindent0pt}
\begin{document}
\tableofcontents
\chapter{test}
\section{test}
\subsection{test}
\chapter{test}
\section{very long titl eee eeee eeeee eee eeee eeeee eee eeee eeeeeeeeeeeeeeee}
\subsection{test}
\chapter{very long titl eee eeee eeeee eee eeee eeeee eee eeee eeeeeeeeeee}
\section{test}
\subsection{very long titl eee eeee eeeee eee eeee eeeee eee eeee eeeee eee eeee eeeee}
\subsection{test}
\section{test}
\subsection{test}
\end{document}