防止目录中的单词分离

防止目录中的单词分离

如何删除目录中的单词分隔符,请看图片。我知道我可以用 来做\chapter[<ToC entry>]{<body entry>},但我需要在序言中有一个解决方案。

\documentclass[10pt,final]{scrbook}
\usepackage{titletoc} % modify toc title
\usepackage{lipsum} % dummy text
\usepackage{anyfontsize} % change fontsize  
\usepackage{tocloft} % design toc
\usepackage{framed, xcolor}
\usepackage[english,ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{helvet}
\usepackage{endnotes}
\usepackage{titlesec}

%%% Change the title of toc
%%% Change "Contents" size \small, \huge, \Large,... 
\addto\captionsngerman{\renewcommand{\contentsname}{\normalfont\slshape\large{Contents}}}

% section itshape
\titleformat*{\section}{\itshape}
\titleformat*{\subsection}{\itshape}
%\titleformat*{\tableofcontents}{\itshape}

% Spacing between section and text
% Syntax: \titlespacing*{<command>}{<left>}{<before-sep>}{<after-sep>}
\titlespacing*{\subsection}{0cm}{0.84cm}{0.42cm}

\titlespacing*{\section}{0cm}{0.84cm}{0.42cm}

% Spacing between chapter and author 
\titlespacing*{\chapter}{0cm}{0.84cm}{0.84cm}

% Spacing between chapterAndAuthor and section (?)
%\titlespacing*{\chapterAndAuthor}{0cm}{1.5cm}{1cm}

%%% Chapter style
\titleformat{\chapter}[display]
  {\normalfont}{\chaptertitlename\ \thechapter}{12pt}{\Large}

% Display chapters in the Table of Contents
\titlecontents{chapter}
  [0pt]% Left margin, optional
  {}% Code insertet above
  {\mdseries}% Numbered-entryformat
  {\mdseries}% Numberless-format
  {\contentspage\vskip1.5ex} % add dotfill and pagenumber, and some vertical space between entries

% Custom command to keep the author on the same page of chaptertitle, and above it.
\newcommand{\chapterAndAuthor}[2]{%
  % #1: Author
  % #2: Chaptertitle
  \clearpage
  % Keep the author and chaptertitle on same page
  \begingroup\let\cleardoublepage\relax\let\clearpage\relax
  % Set the author style
  {\fontsize{12}{14}\itshape \noindent #1}\par
  % Bring the chaptertitle closer to the authortitle
  \vspace{-0.21cm}
  % Add an entry to the Table of Contents, with the name of 
  % the author in emph and the chapter title
  \addcontentsline{toc}{chapter}{%
    \texorpdfstring{%
      \protect\parbox[b]{\dimexpr\textwidth-15.5pt}{
        {\normalfont\itshape {#1}}%
        \endgraf\vspace{0cm}
        \leftskip=1em #2 \dotfill
      }%
    }{#2}%
  }
  % Print the chapter
  \chapter*{#2}
  \endgroup
}

\pagestyle{plain}

\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{graphics}
\usepackage{supertabular}

%SEITENLAYOUT%
 \usepackage[paperheight=21.0cm,paperwidth=13.5cm,twoside,textwidth=10.3cm,textheight=16.3cm,nohead,pdftex]{geometry}

%SCHRIFTGRÃSSEN%
\usepackage{fix-cm}

\makeatletter
\g@addto@macro\normalsize{\fontsize{10.0pt}{12.0pt}\selectfont} %\fontsize{Fontgröße}{Grundlinienabstand}
\g@addto@macro\footnotesize{\fontsize{9.0pt}{11.0pt}\selectfont} %\fontsize{Fontgröße}{Grundlinienabstand}
\makeatother


\usepackage[hyphens]{url}
\usepackage{multicol}
\usepackage[colorlinks=false, pdfborder={0 0 0}, breaklinks = true]{hyperref}
\urlstyle{same}

%%%%%%%%%%%%%%%%% end preambel %%%%%%%%%%%%%

\begin{document}

\tableofcontents
\clearpage


\chapterAndAuthor{The name of the first author, The name of second author and The name of the third author}{Test Chapter One Test Chapter One Test Chapter One Test Chapter One Test Chapter One Test Chapter One Test Chapter One}

\noindent\lipsum[1]

\chapterAndAuthor{Johanna von Orleans, Charles de Secondat, Baron de MontesquieuMontesquieu, , Albert Einstein}{Test Chapter Two Test Chapter Two Test Chapter Two Test Chapter Two Test Chapter Two Test Chapter Two Test Chapter Two}

\noindent\lipsum[1]

\chapterAndAuthor{The name of the first author, The name of second author and The name of the third author}{Test Chapter Three Test Chapter Three Test Chapter Three Test Chapter Three Test Chapter Three Test Chapter Three Test Chapter Three}

\noindent\lipsum[1]



\end{document}

enter image description here

答案1

包裹hyphenat\nohyphens提供防止文本连字的命令:

\usepackage{hyphenat}
\newcommand{\chapterAndAuthor}[2]{%
  % #1: Author
  % #2: Chaptertitle
  \clearpage
  % Keep the author and chaptertitle on same page
  \begingroup\let\cleardoublepage\relax\let\clearpage\relax
  % Set the author style
  {\fontsize{12}{14}\itshape \noindent #1}\par
  % Bring the chaptertitle closer to the authortitle
  \vspace{-0.21cm}
  % Add an entry to the Table of Contents, with the name of 
  % the author in emph and the chapter title
  \addcontentsline{toc}{chapter}{%
    \texorpdfstring{%
      \protect\parbox[b]{\dimexpr\textwidth-15.5pt}{
        {\protect\normalfont\protect\itshape\protect\nohyphens{#1}}%
        \protect\endgraf\protect\vspace{0cm}
        \leftskip=1em #2\protect\dotfill
      }%
    }{#2}%
  }
  % Print the chapter
  \chapter*{#2}
  \endgroup
}

尽管如此,这会导致示例文本的间距非常难看:

ugly result

\raggedright因为理由仍然有效。对于作者来说更好的做法是:

\newcommand{\chapterAndAuthor}[2]{%
  % #1: Author
  % #2: Chaptertitle
  \clearpage
  % Keep the author and chaptertitle on same page
  \begingroup\let\cleardoublepage\relax\let\clearpage\relax
  % Set the author style
  {\fontsize{12}{14}\itshape \noindent #1}\par
  % Bring the chaptertitle closer to the authortitle
  \vspace{-0.21cm}
  % Add an entry to the Table of Contents, with the name of 
  % the author in emph and the chapter title
  \addcontentsline{toc}{chapter}{%
    \texorpdfstring{%
      \protect\parbox[b]{\dimexpr\textwidth-15.5pt}{
        {\protect\raggedright\protect\normalfont\protect\itshape#1%
        \protect\endgraf}\protect\vspace{0cm}
        \leftskip=1em #2\protect\dotfill
      }%
    }{#2}%
  }
  % Print the chapter
  \chapter*{#2}
  \endgroup
}

raggedright used

顺便说一句:查看log文件中的警告,例如:

Class scrbook Warning: Usage of package `titlesec' together
(scrbook)              with a KOMA-Script class is not recommended.
(scrbook)              I'd suggest to use the package only
(scrbook)              if you really need it, because it breaks several
(scrbook)              KOMA-Script features, i.e., option `headings' and
(scrbook)              the extended optional argument of the section
(scrbook)              commands.
(scrbook)              Nevertheless, using requested
(scrbook)              package `titlesec' on input line 14.

和几个

Package titlesec Warning: Non standard sectioning command detected
(titlesec)                Using default spacing and no format.

Package scrbook Warning: Activating an ugly workaround for a missing
(scrbook)                feature of package `titlesec` on input line 14.

我认为您使用的类和包的组合不推荐。也许最好使用\chapterlinesformat\setchapterprefix并将\addchaptertocentry作者信息添加到标题和目录条目中。

答案2

您可以将连字模式切换为nil目录中的语言。问题是,文档中的任何语言切换也会添加\select@language{newlang}.toc文件中,因此只需将

\hyphenrules{nil}

之前\tableofcontents没有帮助。因此,首先,将nil语言添加到 babel 语言列表中:

\usepackage[nil,english,ngerman]{babel}

其次,定义您自己的目录宏,它将禁用以下方式引入的连字符\select@language

\makeatletter
\def\mytableofcontents{%
\let\select@language@orig\select@language
\def\select@language##1{\select@language@orig{##1}\hyphenrules{nil}}%
\tableofcontents
\let\select@language\select@language@orig
}
\makeatother

第三,用这个\mytableofcontents代替\tableofcontents

答案3

要暂时禁用连字,您可以使用\foreignlanguage{nohyphenation}{<text>}。您可能希望目录中没有连字,但将其保留在文档主体中,因此您必须仅在目录中禁用它。由于您使用的是自定义命令,因此您必须相应地更改它们。

这是您需要更改的命令:

\newcommand{\chapterAndAuthor}[2]{%
  % #1: Author
  % #2: Chaptertitle
  \clearpage
  % Keep the author and chaptertitle on same page
  \begingroup\let\cleardoublepage\relax\let\clearpage\relax
  % Set the author style
  {\fontsize{12}{14}\itshape \noindent #1}\par
  % Bring the chaptertitle closer to the authortitle
  \vspace{-0.21cm}
  % Add an entry to the Table of Contents, with the name of 
  % the author in emph and the chapter title
  \addcontentsline{toc}{chapter}{%
    \texorpdfstring{%
      \protect\parbox[b]{\dimexpr\textwidth-15.5pt}{
        {\normalfont\itshape{\foreignlanguage{nohyphenation}{#1}}}% << HERE WE CHANGED
        \endgraf\vspace{0cm}
        \leftskip=1em #2 \dotfill
      }%
    }{#2}%
  }
  % Print the chapter
  \chapter*{#2}
  \endgroup
}

然后我们在目录中就没有连字符了:

enter image description here

但它们仍然可以在文档中发挥作用:

enter image description here

答案4

这是典型的用法,\mbox其实现如下: \mbox{your chain of characters}

这可以防止你的链条出现连字符。请谨慎使用,因为很快就会变得丑陋。

编辑 :

如果您希望它仅在目录中防止连字符,您可以这样做:

 \chapter[\mbox{your chain of characters}]{your chain of characters}

这样做的话,mboxed 标题将被放入目录中,而另一个将用作标题。

编辑2:用以下命令定义替换:

\newcommand{\chapterAndAuthor}[2]{%
 % #1: Author
 % #2: Chaptertitle
\clearpage
 % Keep the author and chaptertitle on same page
\begingroup\let\cleardoublepage\relax\let\clearpage\relax
 % Set the author style
{\fontsize{12}{14}\itshape \noindent #1}\par
 % Bring the chaptertitle closer to the authortitle
\vspace{-0.21cm}
 % Add an entry to the Table of Contents, with the name of 
 % the author in emph and the chapter title
\addcontentsline{toc}{chapter}{%
\texorpdfstring{%
  \protect\parbox[b]{\dimexpr\textwidth-15.5pt}{
    {\normalfont\itshape {\mbox{#1}}}%
    \endgraf\vspace{0cm}
    \leftskip=1em #2 \dotfill
   }%
}{#2}%
}
 % Print the chapter
\chapter*{#2}
\endgroup
}

这是对您之前的命令的先前解决方案的改编。

相关内容