目录:章节标题右侧不齐 - 2

目录:章节标题右侧不齐 - 2

右边的目录不整齐的问题在目录:章节标题右侧不齐针对文章。etoolbox-option 似乎不适用于 book 类,而且由于 tocstyle 是 alpha 版本,因此我不太习惯使用它(例如,使用此包时,我的 toc 中出现了一些未满的 \vbox)。还有其他解决方案吗?以下是 MWE:

\documentclass[b5paper, twoside, 11pt]{book}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@dottedtocline}
  {\rightskip\@tocrmarg}
  {\rightskip\@tocrmarg plus 4em \hyphenpenalty\@M}
  {}{}
\makeatother


\begin{document}

\tableofcontents

\part{A very very long title that is hyphenated and not raggedright even though etoolbox is used}
\part{A very very very long title that is hyphenated and not raggedright even though etoolbox is used}
\part{A very very very very long title that is hyphenated and not raggedright even though etoolbox is used}

\end{document}

通过以下方式获得更全面的 TOC

\documentclass[b5paper, twoside, 11pt]{book}

%\usepackage{etoolbox}
%\makeatletter
%\patchcmd{\@dottedtocline}
%  {\rightskip\@tocrmarg}
%  {\rightskip\@tocrmarg plus 4em \hyphenpenalty\@M}
%  {}{}
%\makeatother


%\usepackage{tocloft}
%\renewcommand{\cftpnumalign}{l}
%\renewcommand{\cftpartleader}{ }    % change \part setting
%\renewcommand{\cftpartafterpnum}{\cftparfillskip}
%\renewcommand{\cftchapleader}{ }    % change \chapter setting
%\renewcommand{\cftchapafterpnum}{\cftparfillskip}
%\renewcommand{\cftsecleader}{ }     % change \section setting
%\renewcommand{\cftsubsecafterpnum}{\cftparfillskip}
%\renewcommand{\cftsubsecleader}{ }     % change \subsection setting
%\renewcommand{\cftsecafterpnum}{\cftparfillskip}


\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  indent=0pt,
  numwidth=0pt,
  raggedentrytext
]{tocline}{part}

\DeclareTOCStyleEntries[
  raggedentrytext
]{tocline}{chapter,section,subsection,subsubsection,paragraph,subparagraph}

\newcommand{\tocseparator}{\vspace{0.5\normalbaselineskip}} % Command used to have slightly larger separation between sectionslist and appendiceslist and referenceslist in toc.
\usepackage{blindtext}
\begin{document}

\tableofcontents

\chapter{Abbreviations}
\Blindtext[10][1]
\chapter{Notation}
\Blindtext[10][1]
\part{Introduction}
\blindtext[10][1]
\section{Background}
\Blindtext[10][1]
\section{Isogeometric analysis}
\Blindtext[10][1]
\subsection{B-splines}
\Blindtext[10][1]
\subsection{B-spline knot insertion}
\Blindtext[10][1]
\subsection{B-spline degree elevation}
\Blindtext[10][1]
\subsection{Spline volumes}
\Blindtext[10][1]
\subsection{NURBS}
\Blindtext[10][1]
\subsection{NURBS knot insertion}
\Blindtext[10][1]
\subsection{The weak form and Galerkin’s method}
\Blindtext[10][1]
\subsection{Assembly}
\Blindtext[10][1]
\subsection{Error analysis}
\Blindtext[10][1]
\section{Helmholtz problems}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Spectral methods}
\Blindtext[10][1]
\subsection{Spectral element method}
\Blindtext[10][1]
\subsection{Method of fundamental solutions}
\Blindtext[10][1]
\section{Summary of Papers}
\Blindtext[10][1]
\subsection{Paper I: Exact 3D scattering solutions for spherical symmetric scatterers}
\Blindtext[10][1]
\subsection{Paper II: Isogeometric Analysis of Acoustic Scattering using Infinite Elements}
\Blindtext[10][1]
\subsection{Paper III: Isogeometric boundary element method}
\Blindtext[10][1]
\subsection{Paper IV: Isogeometric Kirchhoff approximation using numerical steepest descent}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper I – Exact 3D Scattering Solutions for Spherical Symmetric Scatterers}
\section{Introduction}
\Blindtext[10][1]
\section{Governing equations}
\Blindtext[10][1]
\subsection{Governing equations in the time domain}
\Blindtext[10][1]
\subsection{Governing equations in the frequency domain}
\Blindtext[10][1]
\section{General solution in the solid domain}
\Blindtext[10][1]
\subsection{Lam{\'e} solution}
\Blindtext[10][1]
\subsection{Series representation using separation of variables}
\Blindtext[10][1]
\subsection{Expressions for the displacement and stress field}
\Blindtext[10][1]
\subsection{Validation of the displacement and stress formulas}
\Blindtext[10][1]
\section{Establishing constraints from boundary conditions}
\Blindtext[10][1]
\subsection{Notation for the solution in layered domains}
\Blindtext[10][1]
\subsection{Tangential traction conditions}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in intermediate fluid layers}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in the outermost fluid}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in the innermost fluid}
\Blindtext[10][1]
\section{Assembling the linear system of equations}
\Blindtext[10][1]
\subsection{The default case with Neumann-to-Neumann conditions}
\Blindtext[10][1]
\subsection{Alternative boundary conditions}
\Blindtext[10][1]
\subsection{Summary of solution formulas}
\Blindtext[10][1]
\section{Computational aspects}
\Blindtext[10][1]
\subsection{Matrix manipulations}
\Blindtext[10][1]
\subsection{Series evaluation}
\Blindtext[10][1]
\subsection{Round-off errors}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Chang benchmark problem}
\Blindtext[10][1]
\subsection{Ihlenburg benchmark problem}
\Blindtext[10][1]
\subsection{Fender benchmark problem}
\Blindtext[10][1]
\subsection{Benchmark problems}
\Blindtext[10][1]
\subsection{Benchmark problems in the time domain}
\Blindtext[10][1]
\section{Conclusions}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{The spherical coordinate system}
\Blindtext[10][1]
\section{Linear elasticity}
\Blindtext[10][1]
\section{Fundamental functions}
\Blindtext[10][1]
\subsection{Legendre polynomials}
\Blindtext[10][1]
\subsection{Spherical Bessel and Hankel functions}
\Blindtext[10][1]
\section{The incident wave}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper II – Isogeometric Analysis of Acoustic Scattering using Infinite Elements}
\section{Introduction}
\Blindtext[10][1]
\section{Exterior Helmholtz problems}
\Blindtext[10][1]
\subsection{Weak formulation for the Helmholtz equation}
\Blindtext[10][1]
\subsection{Infinite elements}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Acoustic-structure interaction}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Simpson benchmark}
\Blindtext[10][1]
\subsection{Ihlenburg benchmark}
\Blindtext[10][1]
\subsection{Radial pulsation from a mock shell}
\Blindtext[10][1]
\subsection{Stripped BeTSSi submarine}
\section{Conclusions}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{Derivation of bilinear form in infinite elements}
\Blindtext[10][1]
\subsection{The prolate spheroidal coordinate system}
\Blindtext[10][1]
\subsection{Bilinear form for unconjugated Petrov–Galerkin formulation}
\Blindtext[10][1]
\section{Evaluation of radial integrals}
\Blindtext[10][1]
\section{The stripped BeTSSi submarine model}
\Blindtext[10][1]
\section{Approximating NURBS parametrizations with B-spline parametrizations}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper III – Isogeometric Boundary Element Method for Acoustic Scattering by a Submarine}
\section{Introduction}
\Blindtext[10][1]
\section{Helmholtz problems}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Boundary integral equations}
\Blindtext[10][1]
\subsection{Regularization techniques}
\Blindtext[10][1]
\subsection{Rigid scattering problems}
\Blindtext[10][1]
\section{Collocation and Galerkin formulations}
\Blindtext[10][1]
\section{Numerical evaluation of the boundary integrals}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Pulsating sphere}
\Blindtext[10][1]
\subsection{Rigid scattering on a sphere}
\Blindtext[10][1]
\subsection{Torus interior acoustic problem}
\Blindtext[10][1]
\subsection{Manufactured solutions for complex geometries}
\Blindtext[10][1]
\subsection{Manufactured solution with a cube}
\Blindtext[10][1]
\subsection{Manufactured solution with the BeTSSi submarine}
\Blindtext[10][1]
\subsection{Rigid scattering on the BeTSSi submarine}
\Blindtext[10][1]
\section{Conclusions}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{NURBS parametrization of the sphere}
\Blindtext[10][1]
\subsection{Parametrization 1}
\Blindtext[10][1]
\subsection{Parametrization 2}
\Blindtext[10][1]
\section{NURBS parametrization of the torus}
\Blindtext[10][1]
\section{The BeTSSi submarine model}
\Blindtext[10][1]
\subsection{Main body}
\Blindtext[10][1]
\subsection{NACA profiles}
\Blindtext[10][1]
\subsection{Sail}
\Blindtext[10][1]
\subsection{Main rudders}
\Blindtext[10][1]
\subsection{Depth rudders}
\Blindtext[10][1]
\section{An analysis suitable BeTSSi submarine}
\Blindtext[10][1]
\section{Triangulation of the BeTSSi submarine}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper IV – Isogeometric Kirchhoff Approximation using Numerical Steepest Descent}
\section{Introduction}
\Blindtext[10][1]
\section{Kirchhoff approximation}
\Blindtext[10][1]
\section{Numerical steepest descent}
\Blindtext[10][1]
\subsection{Starting value for Newton iterations}
\Blindtext[10][1]
\subsection{The case of no critical points or resonance points in 2D}
\Blindtext[10][1]
\subsection{Resonance points}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Scattering on a rigid sphere}
\Blindtext[10][1]
\section{Conclusion}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Addendum – Spectral Element Analysis of Acoustic Scattering using Infinite Elements}
\section{Introduction}
\Blindtext[10][1]
\section{Lagrange basis functions and GLL nodes}
\Blindtext[10][1]
\section{Geometry approximation}
\Blindtext[10][1]
\section{Exterior Helmholtz problems}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Poisson 1D problem}
\Blindtext[10][1]
\subsection{Rigid scattering on a sphere}
\Blindtext[10][1]
\section{Conclusions}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{A note on the infinite element method}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Appendices}
\section{Derivation of bilinear form for the infinite elements}
\Blindtext[10][1]
\subsection{Numerical examples}
\Blindtext[10][1]
\section{Ray/beam tracing in the isogeometric framework}
\Blindtext[10][1]
\subsection{Beam tracing using linear shape functions}
\Blindtext[10][1]
\subsection{Ray tracing in the isogeometric framework}
\Blindtext[10][1]
\subsection{Computation of reflection and transmission coefficients}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\end{document}

答案1

您可以使用包tocbasic

\documentclass[b5paper, twoside, 11pt]{book}

\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  indent=0pt,
  numwidth=0pt,
  raggedentrytext
]{tocline}{part}

\DeclareTOCStyleEntries[
  raggedentrytext
]{tocline}{chapter,section,subsection,subsubsection,paragraph,subparagraph}

\begin{document}

\tableofcontents

\part{A very very long title that is hyphenated and not raggedright even though etoolbox is used}
\chapter{A chapter with a long unhyphenated title that hopefully is set raggedright}
\section{A section with a long unhyphenated title that hopefully is set raggedright}
\subsection{A subsection with a long unhyphenated title that hopefully is set raggedright}
\subsection{A subsection with a short title}
\part{A very very very long title that is hyphenated and not raggedright even though etoolbox is used}
\part{A very very very very long title that is hyphenated and not raggedright even though etoolbox is used}

\end{document}

结果:

在此处输入图片描述


更新关于问题中的新例子使用更大的页码

您可以pagenumberbox={\mbox}为目录中的部分条目添加选项。也许章节也需要这样做。(目前,第一部分标题后没有章节)。

例子:

\documentclass[b5paper, twoside, 11pt]{book}
\usepackage[paper=b5paper]{geometry}% <- added to get b5paper

%%%% to remove the overfull boxes outside the ToC:
\raggedbottom\pagestyle{plain}
\usepackage[raggedright]{titlesec}% <- raggedright section etc. in document
%%%%

\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  indent=0pt,
  numwidth=0pt,
  pagenumberbox={\mbox},
  raggedentrytext
]{tocline}{part}
\DeclareTOCStyleEntry[
  pagenumberbox={\mbox},
  raggedentrytext
]{tocline}{chapter}

\DeclareTOCStyleEntries[
  raggedentrytext
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph}

\newcommand{\tocseparator}{\vspace{0.5\normalbaselineskip}} % Command used to have slightly larger separation between sectionslist and appendiceslist and referenceslist in toc.
\usepackage{blindtext}
\begin{document}

\tableofcontents

\chapter{Abbreviations}
\Blindtext[10][1]
\chapter{Notation}
\Blindtext[10][1]
\part{Introduction}
\blindtext[10][1]
\section{Background}
\Blindtext[10][1]
\section{Isogeometric analysis}
\Blindtext[10][1]
\subsection{B-splines}
\Blindtext[10][1]
\subsection{B-spline knot insertion}
\Blindtext[10][1]
\subsection{B-spline degree elevation}
\Blindtext[10][1]
\subsection{Spline volumes}
\Blindtext[10][1]
\subsection{NURBS}
\Blindtext[10][1]
\subsection{NURBS knot insertion}
\Blindtext[10][1]
\subsection{The weak form and Galerkin’s method}
\Blindtext[10][1]
\subsection{Assembly}
\Blindtext[10][1]
\subsection{Error analysis}
\Blindtext[10][1]
\section{Helmholtz problems}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Spectral methods}
\Blindtext[10][1]
\subsection{Spectral element method}
\Blindtext[10][1]
\subsection{Method of fundamental solutions}
\Blindtext[10][1]
\section{Summary of Papers}
\Blindtext[10][1]
\subsection{Paper I: Exact 3D scattering solutions for spherical symmetric scatterers}
\Blindtext[10][1]
\subsection{Paper II: Isogeometric Analysis of Acoustic Scattering using Infinite Elements}
\Blindtext[10][1]
\subsection{Paper III: Isogeometric boundary element method}
\Blindtext[10][1]
\subsection{Paper IV: Isogeometric Kirchhoff approximation using numerical steepest descent}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper I – Exact 3D Scattering Solutions for Spherical Symmetric Scatterers}
\section{Introduction}
\Blindtext[10][1]
\section{Governing equations}
\Blindtext[10][1]
\subsection{Governing equations in the time domain}
\Blindtext[10][1]
\subsection{Governing equations in the frequency domain}
\Blindtext[10][1]
\section{General solution in the solid domain}
\Blindtext[10][1]
\subsection{Lam{\'e} solution}
\Blindtext[10][1]
\subsection{Series representation using separation of variables}
\Blindtext[10][1]
\subsection{Expressions for the displacement and stress field}
\Blindtext[10][1]
\subsection{Validation of the displacement and stress formulas}
\Blindtext[10][1]
\section{Establishing constraints from boundary conditions}
\Blindtext[10][1]
\subsection{Notation for the solution in layered domains}
\Blindtext[10][1]
\subsection{Tangential traction conditions}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in intermediate fluid layers}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in the outermost fluid}
\Blindtext[10][1]
\subsection{Displacement and pressure condition in the innermost fluid}
\Blindtext[10][1]
\section{Assembling the linear system of equations}
\Blindtext[10][1]
\subsection{The default case with Neumann-to-Neumann conditions}
\Blindtext[10][1]
\subsection{Alternative boundary conditions}
\Blindtext[10][1]
\subsection{Summary of solution formulas}
\Blindtext[10][1]
\section{Computational aspects}
\Blindtext[10][1]
\subsection{Matrix manipulations}
\Blindtext[10][1]
\subsection{Series evaluation}
\Blindtext[10][1]
\subsection{Round-off errors}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Chang benchmark problem}
\Blindtext[10][1]
\subsection{Ihlenburg benchmark problem}
\Blindtext[10][1]
\subsection{Fender benchmark problem}
\Blindtext[10][1]
\subsection{Benchmark problems}
\Blindtext[10][1]
\subsection{Benchmark problems in the time domain}
\Blindtext[10][1]
\section{Conclusions}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{The spherical coordinate system}
\Blindtext[10][1]
\section{Linear elasticity}
\Blindtext[10][1]
\section{Fundamental functions}
\Blindtext[10][1]
\subsection{Legendre polynomials}
\Blindtext[10][1]
\subsection{Spherical Bessel and Hankel functions}
\Blindtext[10][1]
\section{The incident wave}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper II – Isogeometric Analysis of Acoustic Scattering using Infinite Elements}
\section{Introduction}
\Blindtext[10][1]
\section{Exterior Helmholtz problems}
\Blindtext[10][1]
\subsection{Weak formulation for the Helmholtz equation}
\Blindtext[10][1]
\subsection{Infinite elements}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Acoustic-structure interaction}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Simpson benchmark}
\Blindtext[10][1]
\subsection{Ihlenburg benchmark}
\Blindtext[10][1]
\subsection{Radial pulsation from a mock shell}
\Blindtext[10][1]
\subsection{Stripped BeTSSi submarine}
\section{Conclusions}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{Derivation of bilinear form in infinite elements}
\Blindtext[10][1]
\subsection{The prolate spheroidal coordinate system}
\Blindtext[10][1]
\subsection{Bilinear form for unconjugated Petrov–Galerkin formulation}
\Blindtext[10][1]
\section{Evaluation of radial integrals}
\Blindtext[10][1]
\section{The stripped BeTSSi submarine model}
\Blindtext[10][1]
\section{Approximating NURBS parametrizations with B-spline parametrizations}
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper III – Isogeometric Boundary Element Method for Acoustic Scattering by a Submarine}
\section{Introduction}
\Blindtext[10][1]
\section{Helmholtz problems}
\Blindtext[10][1]
\subsection{Far field pattern}
\Blindtext[10][1]
\section{Boundary integral equations}
\Blindtext[10][1]
\subsection{Regularization techniques}
\Blindtext[10][1]
\subsection{Rigid scattering problems}
\Blindtext[10][1]
\section{Collocation and Galerkin formulations}
\Blindtext[10][1]
\section{Numerical evaluation of the boundary integrals}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Pulsating sphere}
\Blindtext[10][1]
\subsection{Rigid scattering on a sphere}
\Blindtext[10][1]
\subsection{Torus interior acoustic problem}
\Blindtext[10][1]
\subsection{Manufactured solutions for complex geometries}
\Blindtext[10][1]
\subsection{Manufactured solution with a cube}
\Blindtext[10][1]
\subsection{Manufactured solution with the BeTSSi submarine}
\Blindtext[10][1]
\subsection{Rigid scattering on the BeTSSi submarine}
\Blindtext[10][1]
\section{Conclusions}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{NURBS parametrization of the sphere}
\Blindtext[10][1]
\subsection{Parametrization 1}
\Blindtext[10][1]
\subsection{Parametrization 2}
\Blindtext[10][1]
\section{NURBS parametrization of the torus}
\Blindtext[10][1]
\section{The BeTSSi submarine model}
\Blindtext[10][1]
\subsection{Main body}
\Blindtext[10][1]
\subsection{NACA profiles}
\Blindtext[10][1]
\subsection{Sail}
\Blindtext[10][1]
\subsection{Main rudders}
\Blindtext[10][1]
\subsection{Depth rudders}
\Blindtext[10][1]
\section{An analysis suitable BeTSSi submarine}
\Blindtext[10][1]
\section{Triangulation of the BeTSSi submarine}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Paper IV – Isogeometric Kirchhoff Approximation using Numerical Steepest Descent}
\section{Introduction}
\Blindtext[10][1]
\section{Kirchhoff approximation}
\Blindtext[10][1]
\section{Numerical steepest descent}
\Blindtext[10][1]
\subsection{Starting value for Newton iterations}
\Blindtext[10][1]
\subsection{The case of no critical points or resonance points in 2D}
\Blindtext[10][1]
\subsection{Resonance points}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Scattering on a rigid sphere}
\Blindtext[10][1]
\section{Conclusion}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Addendum – Spectral Element Analysis of Acoustic Scattering using Infinite Elements}
\section{Introduction}
\Blindtext[10][1]
\section{Lagrange basis functions and GLL nodes}
\Blindtext[10][1]
\section{Geometry approximation}
\Blindtext[10][1]
\section{Exterior Helmholtz problems}
\Blindtext[10][1]
\section{Numerical examples}
\Blindtext[10][1]
\subsection{Poisson 1D problem}
\Blindtext[10][1]
\subsection{Rigid scattering on a sphere}
\Blindtext[10][1]
\section{Conclusions}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{A note on the infinite element method}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]

\part{Appendices}
\section{Derivation of bilinear form for the infinite elements}
\Blindtext[10][1]
\subsection{Numerical examples}
\Blindtext[10][1]
\section{Ray/beam tracing in the isogeometric framework}
\Blindtext[10][1]
\subsection{Beam tracing using linear shape functions}
\Blindtext[10][1]
\subsection{Ray tracing in the isogeometric framework}
\Blindtext[10][1]
\subsection{Computation of reflection and transmission coefficients}
\Blindtext[10][1]
\addtocontents{toc}{\tocseparator} % add an empty line before references in toc
\section{References}
\Blindtext[10][1]
\end{document}

结果:

在此处输入图片描述

答案2

我不确定你说的 raggedright ToC 是什么意思。不过这个tocloft包可以帮到你。下面是你的 MWE 的修改版本。

% tocraggedprob.tex  SE 511452  set ToC raggedright

\documentclass[b5paper, twoside, 11pt]{book}
\usepackage{comment}

\begin{comment}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@dottedtocline}
  {\rightskip\@tocrmarg}
  {\rightskip\@tocrmarg plus 4em \hyphenpenalty\@M}
  {}{}
\makeatother
\end{comment}

\usepackage{tocloft}
\renewcommand{\cftpnumalign}{l}
\renewcommand{\cftpartleader}{ }    % change \part setting
\renewcommand{\cftpartafterpnum}{\cftparfillskip}
\renewcommand{\cftchapleader}{ }    % change \chapter setting
\renewcommand{\cftchapafterpnum}{\cftparfillskip}
\renewcommand{\cftsecleader}{ }     % change \section setting
\renewcommand{\cftsubsecafterpnum}{\cftparfillskip}
\renewcommand{\cftsubsecleader}{ }     % change \subsection setting
\renewcommand{\cftsecafterpnum}{\cftparfillskip}
% and similarly for \subsection (subsec), \subsubsection (subsubsec),
% \paragraph (para) and \subparagraph (subpara) entries 

\begin{document}

\tableofcontents

\part{A very very long title that is hyphenated and not raggedright even though etoolbox is used}
\chapter{A chapter with a long unhyphenated title that hopefully is set raggedright}
\section{A section with a long unhyphenated title that hopefully is set raggedright}
\subsection{A subsection with a long unhyphenated title that hopefully is set raggedright}
\subsection{A subsection with a short title}
\part{A very very very long title that is hyphenated and not raggedright even though etoolbox is used}
\part{A very very very very long title that is hyphenated and not raggedright even though etoolbox is used}

\end{document}

这会导致页码被设置在条目的末尾,没有虚线。对我来说,这看起来很不合适。

阅读文档(> texdoc tocloft)以了解更多信息。

相关内容