带有两个参数的 texorpdfstring

带有两个参数的 texorpdfstring

第一章和第二章之间的空间不同。我知道问题出在命令\chapterAndAuthor的新命令上texorpfdstring。我添加了命令texorpfdstring以在书签中获取无格式设置。没有texorpfdstring格式设置工作正常。所以我读了texorpfdstring带有两个参数,但无论如何我都无法处理它。请查看 img。(我知道KOMAtitlesec并且titletoc不是一个好方法)。\parbox[t]对我来说不是一个好的解决方案,因为页码不在点后面......

\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}
\usepackage[hyphens]{url}
\usepackage{multicol}
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\urlstyle{same}


\addto\captionsngerman{\renewcommand{\contentsname}{\normalfont{Contents}}}
% section itshape
\titleformat*{\section}{\itshape}
\titleformat*{\subsection}{\itshape}
\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.42cm}
%%% 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} % 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%
    % Minipage to keep the author and chaptertitle on same page
    \noindent\begin{minipage}{\textwidth}
        % Set the author style
        {\selectfont\fontsize{12}{14} \itshape{#1}}
        % Bring the chaptertitle closer to the authortitle
        \vspace{-3\baselineskip}
         % Add an entry to the Table of Contents, with the name of the author in emph and the chapter title
  \addcontentsline{toc}{chapter}{\texorpdfstring{\normalfont #1\vspace{1ex}\newline
    % For long chapter titles using a \parbox
    \hspace*{1em}\protect\parbox[b]{\textwidth}{#2 \dotfill}}{#2}}
  % Print the chapter
        \chapter*{#2}
    \end{minipage}
    }


% space between table of contents
\setlength\cftparskip{0.21cm} 
\setlength\cftbeforesecskip{10pt}
\setlength\cftaftertoctitleskip{10pt} 
%pagestyle%
\usepackage[paperheight=21.0cm,paperwidth=13.5cm,twoside,textwidth=10.3cm,textheight=16.3cm,nohead,pdftex]{geometry}
\pagestyle{plain}

\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}
\lipsum[1-4]
\vspace{0.84cm}
\subsection*{Subheading1 without indentation}
\lipsum[1-4]
\subsection*{Subheading2 without indentation}
\lipsum[1-2]
\subsection*{Subheading3 without indentation}
\lipsum[1-2]
\chapterAndAuthor{The name of the second author}{Test Chapter Two}
\lipsum[1-5]

\end{document}

在此处输入图片描述

答案1

您应该将所有内容括在里面\parbox,而不仅仅是章节标题。

顺便说一句,您不应该同时加载titletoctocloft-15pt位应该对应于中的某个参数titletoc,找出哪一个。

还可以更好地区分目录中的标题。

为了举例,我删除了大部分不必要的包。将\contentsname内容更改为德语是可疑的:如果文档是英文的,但部​​分内容是德文,则在声明中切换语言的位置:\usepackage[ngerman,english]{babel}

\documentclass[10pt,draft]{scrbook}

\usepackage{titlesec}
\usepackage{titletoc} % modify toc title
\usepackage{lipsum} % dummy text
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\urlstyle{same}

% section itshape
\titleformat*{\section}{\itshape}
\titleformat*{\subsection}{\itshape}
\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.42cm}
%%% 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} % 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
  \cleardoublepage
  % 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{-3\baselineskip}
  % 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 #1%
        \endgraf\vspace{1ex}
        \leftskip=1em #2 \dotfill
      }%
    }{#2}%
  }
  % Print the chapter
  \chapter*{#2}
  \endgroup
}


% space between table of contents
%pagestyle%
\usepackage[
  paperheight=21.0cm,
  paperwidth=13.5cm,
  twoside,
  textwidth=10.3cm,
  textheight=16.3cm,
  nohead,
  showframe, % <---- Just for the example
]{geometry}
\pagestyle{plain}

\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}
\lipsum[1-4]
\vspace{0.84cm}
\subsection*{Subheading1 without indentation}
\lipsum[1-4]
\subsection*{Subheading2 without indentation}
\lipsum[1-2]
\subsection*{Subheading3 without indentation}
\lipsum[1-2]
\chapterAndAuthor{The name of the second author}{Test Chapter Two}
\lipsum[1-5]

\end{document}

在此处输入图片描述

相关内容