scrbook 目录中两行标题的对齐方式

scrbook 目录中两行标题的对齐方式

我已经检查了其他几个解决类似问题的问题,但我仍然无法按照我想要的方式调整我的文档。

我有以下两行章节标题:

在此处输入图片描述

在目录中看起来很糟糕,跨越 3 行:

在此处输入图片描述

我尝试使用\\在目录中部分起作用的方法(我仍然需要找出如何将第 2 行中的第一个单词放在第 1 行的第一个单词正下方),但在章节标题中添加了一行额外的行,而这并不是我想要的。

在此处输入图片描述

在此处输入图片描述

我知道的可选参数\chapter[text in TOC]{Chapter title},但我不想对同一章使用 2 个名称。

我尝试\chapter[Control Strategies for Wave Energy Converters: \\ State-of-the-Art]{Control Strategies for Wave Energy Converters: State-of-the-Art}在目录中按我想要的方式换行,并修复了章节标题中多一行的问题(我仍然需要找出如何将第 2 行的第一个单词放在第 1 行的第一个单词的正下方)。缺点是,我收到一条警告“Package hyperref 警告:PDF 字符串中不允许使用标记(Unicode):删除输入行 180 上的“\””

我也尝试\texorpdfstring{}{}贡萨洛

\chapter{ \texorpdfstring{Control Strategies for Wave Energy Converters:\\ State-of-the-Art}{Control Strategies for Wave Energy Converters: State-of-the-Art} }

但我得到的结果与仅使用 相同\\

有什么指导吗?

欢呼!

以下是整个“MWE”(抱歉,可能不是那么最低限度):

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=3cm,bottom=3cm,
            bindingoffset=0cm,includefoot=false,twoside]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[pdftex]{graphicx}
\usepackage{titletoc}
\usepackage{hyperref}
\hypersetup{plainpages=false, colorlinks=true,citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
pdfpagemode=FullScreen,pdfborder={0 0 0}, breaklinks=true,  bookmarksnumbered=true, bookmarksopen=true}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\definecolor{maincolor}{cmyk}{1, .50, .10, .01}
%% Define some format spacing---------------------------------------------------------
\setlength{\parindent}{1em}\selectfont
\setlength{\parskip}{1em}\selectfont
\renewcommand{\baselinestretch}{1.25}\selectfont
%% Title format for Chapters -------------------------------------------------------
\newcommand{\ssfont}{\fontfamily{bch}\selectfont}
\newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont}
\newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont}
\newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont}
\newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize}
\newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries}
% headings
\setkomafont{chapter}{\thesischapterfont}
\setkomafont{section}{\thesissectionfont}
\setkomafont{subsection}{\thesissubsectionfont}

%%  Header and Footer ----------------------------------------------------------------------
\automark[section]{chapter} 
\setlength{\headheight}{19pt} 
\setlength{\footheight}{160pt} 
\setlength{\footskip}{185pt}
\KOMAoption{footwidth}{foot:53pt}
\setkomafont{pagefoot}{\fontfootertext}
\setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC ---------------------------------------------
\titlecontents{chapter}[0pc]{\addvspace{1pc}}
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7) node[align=center,font=\color{white}\large\scshape\bfseries, xshift=-1.8cm,yshift=-0.5cm]{Chapter\ \thecontentslabel};
\end{tikzpicture}\hspace{1.5cm}\color{maincolor!90}\large\scshape\bfseries}
{\hspace{1.5cm}\color{maincolor!90}\large\scshape\bfseries}
{\color{maincolor!90}\;\dotfill\quad\large\scshape\bfseries\thecontentspage}[\addvspace{0pc}]
%*****************************************************
\titlecontents{section}[2.4pc]{\addvspace{0pc}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}{}
{\;\dotfill\;\normalsize \thecontentspage} [\addvspace{-0.5pc}]
%*****************************************************
\titlecontents{subsection}[5pc]{\addvspace{0pc}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}{}
{\;\dotfill\;\normalsize\thecontentspage} [\addvspace{-0.5pc}]
%*****************************************************
\makeatletter
\renewcommand{\tableofcontents}{
\chapter*{
\vspace*{-1cm}
\begin{tikzpicture}[remember picture, overlay]
% Output the chapter image
\clip (current page.north west) rectangle ([yshift=-8cm]current page.north east);
\node[anchor=north west,inner sep=0pt] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}};
% Box with the chapter title
\draw[anchor=west] (current page.north west) node [
        anchor=north west, xshift=3cm, yshift=-3.5cm,
        line width=2pt, rounded corners=10pt, 
        draw=maincolor, fill=black!5,
        fill opacity=0.1, text opacity=1,
        inner ysep=12.5pt, inner xsep=20pt,
        align=flush left, text width=1.2\linewidth,
        font=\Huge\sffamily\scshape\bfseries\color{maincolor}] { \contentsname };
\end{tikzpicture}}
\@starttoc{toc}}
\makeatother

% Begin document ---------------------------------------------
\begin{document}
    \frontmatter 
    \pagenumbering{roman}
    \pagestyle{empty}   
    \setcounter{tocdepth}{2}
    \tableofcontents        
    \cleardoublepage
    \mainmatter
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \pagestyle{headings}
% Chapter 1 -----------------------------------
    \chapter{Introduction}
    \lipsum[1-3]
    \section{Section 1}
    \lipsum[1-5]
        \subsection{Subsection 1}
        \lipsum[1-3]
        \subsection{Subsection 2}
        \lipsum[1-3]
    \section{Section 2}
    \lipsum[1-3]
% Chapter 2 -----------------------------------
\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art}
    \lipsum[1-3]
    \section{Section 1}
    \lipsum[1-5]
        \subsection{Subsection 1}
        \lipsum[1-3]
        \subsection{Subsection 2}
        \lipsum[1-3]
    \section{Section 2}
    \lipsum[1-3]
% Chapter 3 -----------------------------------
\chapter{Optimal Control for Wave Energy Converters: Contributions}
    \section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach}
        \lipsum[1-3]
        \section{Section 1}
        \lipsum[1-3]
        \section{Section 2}
        \lipsum[1-3]

    \section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters}
        \lipsum[1-3]
        \section{Section 1}
        \lipsum[1-3]
        \section{Section 2}
        \lipsum[1-3]

    \section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim}
        \lipsum[1-3]
        \section{Section 1}
        \lipsum[1-3]
        \section{Section 2}
        \lipsum[1-3]

\end{document}

编辑版本:我尝试了@Jasper 的建议,但仍然无济于事:使用“正常”\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art}\chapter{Optimal Control for Wave Energy Converters: Contributions}

在此处输入图片描述

答案1

尝试使用此代码进行 ToC 章节定义:

\titlecontents{chapter}[2.4pc]{\addvspace{1pc}}
{%
\begin{tikzpicture}[remember picture, overlay,box/.style = {text width=3cm, font=\color{white}\large\scshape\bfseries}]
    \node (rect) at (-2.5,1ex) [box, draw,thick,minimum width=4cm,minimum height=1cm, fill=maincolor!90,draw=maincolor!90,rounded corners=5pt,align=right ] {Chapter\ \thecontentslabel};       
\end{tikzpicture}   
\hspace*{-1ex}\color{maincolor!90}\large\scshape\bfseries}{}
{\color{maincolor!90}\large\scshape\bfseries\;\dotfill\thecontentspage}
[\addvspace{0pc}]

b

答案2

这是不使用包的建议titletoc。KOMA-Script 类会自动scrbook加载包tocbasic。因此,它可用于格式化目录条目和目录头。

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[
  hmargin=2.5cm,vmargin=3cm,
  footskip=185pt,includefoot=false
  ]{geometry}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\PassOptionsToPackage{xcolor}{dvipsnames}
\usepackage{tikz}% loads xcolor,graphicx etc.
\usepackage{hyperref}% load after other packages
\hypersetup{
  plainpages=false,
  colorlinks=true, citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
  pdfpagemode=FullScreen,pdfborder={0 0 0},
  breaklinks=true,
  bookmarksnumbered=true, bookmarksopen=true
}

\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\definecolor{maincolor}{cmyk}{1, .50, .10, .01}
%% Define some format spacing---------------------------------------------------------
\setparsizes{1em}{1em plus .1\baselineskip}{0pt plus 1fil}% do not change \parindent and \parskip manuelly
\renewcommand{\baselinestretch}{1.25}\selectfont
%% Title format for Chapters -------------------------------------------------------
\newcommand{\ssfont}{\fontfamily{bch}\selectfont}
\newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont}
\newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont}
\newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont}
\newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize}
\newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries}
% headings
\setkomafont{chapter}{\thesischapterfont}
\setkomafont{section}{\thesissectionfont}
\setkomafont{subsection}{\thesissubsectionfont}

%%  Header and Footer ----------------------------------------------------------------------
\automark[section]{chapter} 
\setlength{\headheight}{19pt} 
\setlength{\footheight}{160pt} 
\setlength{\footskip}{185pt}
\KOMAoption{footwidth}{foot:53pt}
\setkomafont{pagefoot}{\fontfootertext}
\setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC ---------------------------------------------
\addtokomafont{chapterentry}{\large}
\addtokomafont{chapterentrydots}{\color{maincolor!90}}
\addtokomafont{chapterentrypagenumber}{\color{maincolor!90}}

\newcommand{\chapterentryformat}[1]{%
  \begin{tikzpicture}[remember picture, overlay]
  \draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt]
    (-2.8,-.2) rectangle (1,.7)
      node[align=center,font=\color{white}\large\bfseries, xshift=-1.8cm,yshift=-0.5cm]
      {\chaptername\ #1};
  \end{tikzpicture}%
}

\DeclareTOCStyleEntry[
  entrynumberformat=\chapterentryformat,
  numwidth=1.75cm,
  raggedentrytext=true,
  linefill=\usekomafont{chapterentrydots}{\TOCLineLeaderFill}
]{tocline}{chapter}
\DeclareTOCStyleEntries[dynindent]{tocline}{section,subsection}

\makeatletter
\renewcommand{\@dotsep}{2.5}% adjust the space between the filler dots, default is 4.5
\makeatother

\deftocheading{toc}{%
  \cleardoublepage
  \begin{tikzpicture}[remember picture, overlay]
    % Output the chapter image
    \clip (current page.north west) rectangle ([yshift=-8cm]current page.north east);
    \node[anchor=north west,inner sep=0pt] at (current page.north west)
      {\includegraphics[width=\paperwidth]{example-image-a}};
  % Box with the chapter title
    \draw[anchor=west] 
      (current page.north west) node [
          anchor=north west, xshift=3cm, yshift=-3.5cm,
          line width=2pt, rounded corners=10pt, 
          draw=maincolor, fill=black!5,
          fill opacity=0.1, text opacity=1,
          inner ysep=12.5pt, inner xsep=20pt,
          align=flush left, text width=1.2\linewidth,
          font=\Huge\sffamily\bfseries\color{maincolor}]
        { \contentsname };
  \end{tikzpicture}%
  \vspace{5cm}\par
}

\setcounter{tocdepth}{2}

\begin{document}
\frontmatter 
\pagestyle{empty}
\tableofcontents

\mainmatter
\pagestyle{headings}% headings is an alias of scrheadings (because of package scrlayer-scrpage)

\chapter{Introduction}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-5]
\subsection{Subsection 1}
\lipsum[1-3]
\subsection{Subsection 2}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]

\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-5]
\subsection{Subsection 1}
\lipsum[1-3]
\subsection{Subsection 2}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]

\chapter{Optimal Control for Wave Energy Converters: Contributions}
\section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\end{document}

在此处输入图片描述

或者,如果您raggedentrytext=true从章节条目的设置中删除选项:

在此处输入图片描述


如果你需要在目录中手动换行,你可以使用

\documentclass[...,headings=optiontoheadandtoc]{scrbook}

\chapter
  [tocentry={\texorpdfstring{Optimal Control for Wave Energy Converters:\\ Contributions}{Optimal Control for Wave Energy Converters: Contributions}}]
  {Optimal Control for Wave Energy Converters: Contributions}

然后换行符只影响目录条目。

例子:

\documentclass[twoside,12pt,openright,headings=optiontoheadandtoc]{scrbook}
\usepackage[
  hmargin=2.5cm,vmargin=3cm,
  footskip=185pt,includefoot=false
  ]{geometry}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\PassOptionsToPackage{xcolor}{dvipsnames}
\usepackage{tikz}% loads xcolor,graphicx etc.
\usepackage{hyperref}% load after other packages
\hypersetup{
  plainpages=false,
  colorlinks=true, citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
  pdfpagemode=FullScreen,pdfborder={0 0 0},
  breaklinks=true,
  bookmarksnumbered=true, bookmarksopen=true
}

\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\definecolor{maincolor}{cmyk}{1, .50, .10, .01}
%% Define some format spacing---------------------------------------------------------
\setparsizes{1em}{1em plus .1\baselineskip}{0pt plus 1fil}% do not change \parindent and \parskip manuelly
\renewcommand{\baselinestretch}{1.25}\selectfont
%% Title format for Chapters -------------------------------------------------------
\newcommand{\ssfont}{\fontfamily{bch}\selectfont}
\newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont}
\newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont}
\newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont}
\newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize}
\newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries}
% headings
\setkomafont{chapter}{\thesischapterfont}
\setkomafont{section}{\thesissectionfont}
\setkomafont{subsection}{\thesissubsectionfont}

%%  Header and Footer ----------------------------------------------------------------------
\automark[section]{chapter} 
\setlength{\headheight}{19pt} 
\setlength{\footheight}{160pt} 
\setlength{\footskip}{185pt}
\KOMAoption{footwidth}{foot:53pt}
\setkomafont{pagefoot}{\fontfootertext}
\setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC ---------------------------------------------
\addtokomafont{chapterentry}{\large}
\addtokomafont{chapterentrydots}{\color{maincolor!90}}
\addtokomafont{chapterentrypagenumber}{\color{maincolor!90}}

\newcommand{\chapterentryformat}[1]{%
  \begin{tikzpicture}[remember picture, overlay]
  \draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt]
    (-2.8,-.2) rectangle (1,.7)
      node[align=center,font=\color{white}\large\bfseries, xshift=-1.8cm,yshift=-0.5cm]
      {\chaptername\ #1};
  \end{tikzpicture}%
}

\DeclareTOCStyleEntry[
  entrynumberformat=\chapterentryformat,
  numwidth=1.75cm,
  raggedentrytext=true,
  linefill=\usekomafont{chapterentrydots}{\TOCLineLeaderFill}
]{tocline}{chapter}
\DeclareTOCStyleEntries[dynindent]{tocline}{section,subsection}

\makeatletter
\renewcommand{\@dotsep}{2.5}% adjust the space between the filler dots, default is 4.5
\makeatother

\deftocheading{toc}{%
  \cleardoublepage
  \begin{tikzpicture}[remember picture, overlay]
    % Output the chapter image
    \clip (current page.north west) rectangle ([yshift=-8cm]current page.north east);
    \node[anchor=north west,inner sep=0pt] at (current page.north west)
      {\includegraphics[width=\paperwidth]{example-image-a}};
  % Box with the chapter title
    \draw[anchor=west] 
      (current page.north west) node [
          anchor=north west, xshift=3cm, yshift=-3.5cm,
          line width=2pt, rounded corners=10pt, 
          draw=maincolor, fill=black!5,
          fill opacity=0.1, text opacity=1,
          inner ysep=12.5pt, inner xsep=20pt,
          align=flush left, text width=1.2\linewidth,
          font=\Huge\sffamily\bfseries\color{maincolor}]
        { \contentsname };
  \end{tikzpicture}%
  \vspace{5cm}\par
}

\setcounter{tocdepth}{2}

\begin{document}
\frontmatter 
\pagestyle{empty}
\tableofcontents

\mainmatter
\pagestyle{headings}% headings is an alias of scrheadings (because of package scrlayer-scrpage)

\chapter{Introduction}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-5]
\subsection{Subsection 1}
\lipsum[1-3]
\subsection{Subsection 2}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]

\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-5]
\subsection{Subsection 1}
\lipsum[1-3]
\subsection{Subsection 2}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]

\chapter
  [tocentry={\texorpdfstring{Optimal Control for Wave Energy Converters:\\ Contributions}{Optimal Control for Wave Energy Converters: Contributions}}]
  {Optimal Control for Wave Energy Converters: Contributions}
\section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim}
\lipsum[1-3]
\section{Section 1}
\lipsum[1-3]
\section{Section 2}
\lipsum[1-3]
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容