目录中的长标题无法正确拆分

目录中的长标题无法正确拆分

我的目录似乎无法很好地处理标题,因为标题有点太长了。以下是屏幕截图:

如您所见,有些行断了,但有些行(例如第 9.15 节的标题)没有断。

这是我用于该文档的类和包。

\documentclass[paper=A5, fontsize=8pt, DIV=calc, pagesize=auto, oneside]{scrbook}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[subsectionbib]{bibunits}
\usepackage[left= 7.5em, right= 7.5em, bottom=13em]{geometry}
\usepackage[pdftex,hyperref]{xcolor} % pdf color support
\usepackage{tocstyle}
\usetocstyle{standard}
\usepackage[colorlinks,linktocpage]{hyperref}
\hypersetup{
   colorlinks   = true, %Colours links instead of ugly boxes
   urlcolor     = blue, %Colour for external hyperlinks
   linkcolor    = blue, %Colour of internal links
   citecolor   = red %Colour of citations
 } 

\begin{document}

\tableofcontents   


\chapter{some long title which is just a little bit too long}

\end{document} 

添加行后

  \makeatletter
    \def\@pnumwidth{2em}
  \makeatother

正如 Gustavo 所建议的,结果如下:

在此处输入图片描述

编辑:在使用 tocstyle 包之前,请注意第 10.10 节之后缺少空格。此时,所有标题均正确断开。

在此处输入图片描述

答案1

笔记: 为了使其更顺畅,该答案已由其原作者彻底编辑过。

事实上,标准类或 LaTeX 内核\l@chapter分别实现该命令或\@dottedtocline命令,使得目录(或类似表格,如图表列表)中偶尔会出现此类不幸的换行符。除非引用的页码宽度足够宽,否则问题并不明显。

为了弄清问题的根源,首先考虑以下简单示例,其中标准类(但同样的讨论也适用于其他类,包括记事本):

\documentclass[a5paper]{book}
\usepackage[T1]{fontenc}
\usepackage[left= 7.5em, right= 7.5em, bottom=13em]{geometry}
\usepackage[colorlinks,linktocpage]{hyperref}
\hypersetup{
   colorlinks   = true, %Colours links instead of ugly boxes
   urlcolor     = blue, %Colour for external hyperlinks
   linkcolor    = blue, %Colour of internal links
   citecolor    = red   %Colour of citations
}



\begin{document}

\tableofcontents

\setcounter{page}{333}

\chapter{Quality of Service Optimization in Self-adapti\-ve}

Blah blah.

\chapter{Quality of Service Optimization in Self-adapti}

Foo bar.

\section{I should be sleeping now\ldots}
\ldots and not trying to post silly answer to \TeX.SX when I~am evidently too 
tired to reason correctly!


\section{I'll go}
Good night to everybody.

\section[Lorem ipsum dolor sit amet consectetur adipisci elit enim ut fugiat]
Some text.

\end{document}

它产生以下输出: 原始版本

将其与以下可能的补丁产生的输出进行比较(再次,适合标准book类):

\documentclass[a5paper]{book}
\usepackage[T1]{fontenc}
\usepackage[left= 7.5em, right= 7.5em, bottom=13em]{geometry}
\usepackage[colorlinks,linktocpage]{hyperref}
\hypersetup{
   colorlinks   = true, %Colours links instead of ugly boxes
   urlcolor     = blue, %Colour for external hyperlinks
   linkcolor    = blue, %Colour of internal links
   citecolor    = red   %Colour of citations
}

\makeatletter
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hskip .5em \@plus 1fil % <<< MODIFICATION <<<
      \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother



\begin{document}

\tableofcontents

\setcounter{page}{333}

\chapter{Quality of Service Optimization in Self-adapti\-ve}

Blah blah.

\chapter{Quality of Service Optimization in Self-adapti}

Foo bar.

\section{I should be sleeping now\ldots}
\ldots and not trying to post silly answer to \TeX.SX when I~am evidently too 
tired to reason correctly!


\section{I'll go}
Good night to everybody.

\section[Lorem ipsum dolor sit amet consectetur adipisci elit enim ut fugiat]
Some text.

\end{document}

这里是: 第一个(毫无意义的)补丁

如您所见,.5em在条目文本和页码之间插入的额外空格强制进行所需的换行。

当然,这个补丁毫无意义,因为调整起来更简单、更通用\@pnumwidth,就像我们在下面的代码中所做的那样:

\documentclass[a5paper]{book}
\usepackage[T1]{fontenc}
\usepackage[left= 7.5em, right= 7.5em, bottom=13em]{geometry}
\usepackage[colorlinks,linktocpage]{hyperref}
\hypersetup{
   colorlinks   = true, %Colours links instead of ugly boxes
   urlcolor     = blue, %Colour for external hyperlinks
   linkcolor    = blue, %Colour of internal links
   citecolor    = red   %Colour of citations
}


\begin{document}

\makeatletter
  \def\@pnumwidth{2em}
  \def\@tocrmarg {3.5em} % Also advisable
\makeatother

\tableofcontents

\setcounter{page}{333}

\chapter{Quality of Service Optimization in Self-adapti\-ve}

Blah blah.

\chapter{Quality of Service Optimization in Self-adapti}

Foo bar.

\section{I should be sleeping now\ldots}
\ldots and not trying to post silly answer to \TeX.SX when I~am evidently too 
tired to reason correctly!


\section{I'll go}
Good night to everybody.

\section[Lorem ipsum dolor sit amet consectetur adipisci elit enim ut fugiat]
Some text.

\end{document}

结果: 第二个(更简单)补丁

但是,有人可能会反对,为了给页码留出更多空间,此解决方案会导致前导符(“点”)更早地停止在行上。这应该不是问题,但如果是,还有另一种补救措施是可行的,如下所示。请注意,在这种情况下,需要\@dottedtocline修补命令(以及),因为前导符仅出现在通过此命令生成的部分和较低级别标题的条目中。还请注意,为了显示修补程序确实有效,此示例中的点彼此之间的距离更近了。

\documentclass[a5paper]{book}
\usepackage[T1]{fontenc}
\usepackage[left= 7.5em, right= 7.5em, bottom=13em]{geometry}
\usepackage[colorlinks,linktocpage]{hyperref}
\hypersetup{
   colorlinks   = true, %Colours links instead of ugly boxes
   urlcolor     = blue, %Colour for external hyperlinks
   linkcolor    = blue, %Colour of internal links
   citecolor    = red   %Colour of citations
}

\makeatletter

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hskip .5em \@plus 1fil % <<< MODIFICATION <<<
      \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hskip .5em \@plus 1fil % <<< MODIFICATION <<<
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi}
  \def\@dotsep{1.5} % <<< REMOVE THIS LINE! (It's included only to make the 
                    % result visible.)

\makeatother



\begin{document}

\tableofcontents

\setcounter{page}{333}

\chapter{Quality of Service Optimization in Self-adapti\-ve}

Blah blah.

\chapter{Quality of Service Optimization in Self-adapti}

Foo bar.

\section{I should be sleeping now\ldots}
\ldots and not trying to post silly answer to \TeX.SX when I~am evidently too 
tired to reason correctly!


\section{I'll go}
Good night to everybody.

\section[Lorem ipsum dolor sit amet consectetur adipisci it]
Some text.

\end{document}

最后一个例子的输出: 第三个(精炼)补丁

需要强调的是,第一个和最后一个补丁不能盲目应用记录除以下类别之外的类别或者在使用特定包时;另一方面,第二种方法在更普遍的情况下更有可能发挥作用。

最后,我认为值得一提的是,我们正在讨论的问题是不是解决fixltx2e包裹。

答案2

我无法重现您报告的问题。更正后,我无需进一步更改即可进行编译,并且输出看起来不错:

正确输出

我只是在这里猜测,但我认为你可能遇到了连字符问题。事实上,我能够得到类似于你的输出,将单词“Networks”放入 中\mbox{}。尝试像这样写章节名称:

\chapter{Quality of Service Optimization in Self-adaptive Sensor Net\-works}

所以你帮助 latex 正确地进行分解。希望有帮助!

相关内容