目录,长标题内的缩进

目录,长标题内的缩进

我的问题与以下问题类似: 目录:各部分的漂亮标题

然而,该解决方案并不足以解决我的问题。

我的问题是:在目录中,我有一个两行的标题,我需要将标题的第二行从第一行缩进 0.25 英寸。

我使用的包的TOC定义中的定义\l@part如下:

\newcommand\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty{-\@highpenalty}%
\addvspace{2.25em \@plus\p@}%
\begingroup
  \setlength\@tempdima{3em}%
  \parindent \z@ \rightskip \@pnumwidth
  \parfillskip -\@pnumwidth
  {\leavevmode
   \bfseries #1\hfil \hbox to\@pnumwidth{\hss #2}}\par
   \nobreak
     \global\@nobreaktrue
     \everypar{\global\@nobreakfalse\everypar{}}
\endgroup
\fi}

我之前尝试添加以下内容\nobreak

\advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...

我确信我遗漏了一点小东西来使一切正常运转,但我搞不清楚。另外,我认为这个解决方案行不通,因为我需要指定 的空间.25''

给出的解决方案似乎只将第二行缩进与第一行一样多。所以我添加了\hspace{.25in}after \leftskip,但它也没有用。

谢谢。

答案1

贡萨洛的回答修改的。

\documentclass{book}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%NEW
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode\large\bfseries\hangindent0.25in\hangafter1    %% here changed
      \advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}\makeatother

\begin{document}

\tableofcontents

\part{Test part one with a really really long title spanning two lines}
\part{Test part two with a really really long title spanning two lines}
\part{Test part three with a really really long title spanning two lines}
\part{Test part four with a really really long title spanning two lines}

\end{document}

在此处输入图片描述

\hangindent0.25in\hangafter1我已在适当的位置添加。

答案2

我也遇到了同样的问题。我所做的是

\newcommand\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty{-\@highpenalty}%
\addvspace{2.25em \@plus\p@}%
\begingroup
  \setlength\@tempdima{3em}%
  \parindent \z@ \rightskip \@pnumwidth
  \parfillskip -\@pnumwidth
  
  % i started changing from here

  \leavevmode                  % removed the opening brace
  \bfseries
  \advance\leftskip\@tempdima  % added this line
  \hskip -\leftskip            % added this line too
  #1\hfil \hbox to\@pnumwidth{\hss #2}\par % removed the closing brace
  \nobreak
  \global\@nobreaktrue
  \everypar{\global\@nobreakfalse\everypar{}}
\endgroup
\fi}

试试这个。我不知道问题是什么。我从这里得到了一些想法:“\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip”的含义

相关内容