将章节标题拆分为两行或更多行

将章节标题拆分为两行或更多行

在下面的代码中,如果章节标题太长,文本将无法在页面上显示。如果章节标题太长,我希望帮助让标题文本显示在两行(或更多行)上。

对于下面给出的示例代码,名为“Matlab 算法列表”的章节是有问题的章节。您能帮我把该章节改成这样吗:

在此处输入图片描述

以下是代码:

\documentclass{book}
\usepackage{tikz}
\usepackage{fourier}
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{lipsum}

\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\renewcommand\thechapter{\arabic{chapter}}

\newcommand\chapnumfont{%
  \fontsize{60}{130}\color{myblueii}\scshape\bfseries%
}

\newcommand\chapnamefont{%
  \normalfont\color{white}\scshape\small\bfseries
}

\titleformat{\chapter}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-10cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=13cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {\thechapter};%
    {};
  \node[
      anchor=south east,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont #1};
    {};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \end{tikzpicture}%
  }

\titleformat{name=\chapter,numberless}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-10cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=13cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {};%
  \node[
      anchor=south east,minimum width=2in,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont #1};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \end{tikzpicture}%
  }

\begin{document}

\pagestyle{empty} % No headers

\tableofcontents % Print the table of contents itself

\listoffigures

\listoftables

\chapter{Problem}

\lipsum[1]
\section{Problem Statement 1}
\lipsum[1]

\chapter{List of Matlab Algorithms}
\section{Algorithm 1}
\lipsum[1]

\renewcommand{\chaptername}{Appendix}
\renewcommand{\leftmark}{\sffamily\normalsize\bfseries \appendixname~\thechapter}
\appendix
\chapter{References}

\end{document} 

答案1

这是一个解决方案。 在此处输入图片描述

  1. 允许使用换行符text width=.6\paperwidth
  2. 与……对齐align=right
  3. 行间空间使用字体选项font=\chapnumfont

注 1我重新定义\chapnumfont

\newcommand\chapnumfont{%
      \fontsize{60}{72}\selectfont\color{myblueii}\bfseries%
    }

此处字体大小为 60pt,行间间距为 72pt,因此行间间距 = 1.2 * 字体大小

笔记2 如果需要,您必须完成无号(带星号)章节的更改。


\documentclass{book}
\usepackage{tikz}
\usepackage{fourier}

\usepackage[explicit,calcwidth]{titlesec}
\usepackage{lipsum}

\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\renewcommand\thechapter{\arabic{chapter}}

\newcommand\chapnumfont{%
  \fontsize{60}{72}\selectfont\color{myblueii}\bfseries%
}

\newcommand\chapnamefont{%
  \normalfont\color{white}\scshape\small\bfseries
}

\titleformat{\chapter}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-10cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=13cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {\thechapter};%
    {};
  \node[
      text width=.6\paperwidth, align=right, font=\chapnumfont,
      anchor=south east,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {#1};
    {};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \end{tikzpicture}%
  }

\titleformat{name=\chapter,numberless}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-10cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=13cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {};%
  \node[
      anchor=south east,minimum width=2in,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont #1};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \end{tikzpicture}%
  }

\begin{document}

\pagestyle{empty} % No headers

\tableofcontents % Print the table of contents itself

\listoffigures

\listoftables

\chapter{Problem}

\lipsum[1]
\section{Problem Statement 1}
\lipsum[1]

\chapter{List of Matlab Algorithms}
\section{Algorithm 1}
\lipsum[1]

\renewcommand{\chaptername}{Appendix}
\renewcommand{\leftmark}{\sffamily\normalsize\bfseries \appendixname~\thechapter}
\appendix
\chapter{References}

\end{document}

相关内容