將符號加入章節標題

將符號加入章節標題

我想添加“|”符號或垂直線,添加到章節標題,使其看起來像這樣:

這是原始程式碼:

\documentclass[svgnames]{book}

\usepackage{tikz}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}

\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\begin{document}
\tableofcontents
\chapter{Decision Trees}
Text
\chapter{Main}

\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference

\end{thebibliography}
\end{document} 

答案1

\chapterlabel #1是插入垂直線的地方。\chapterlabel對於未編號的章節為空,或包含包含尾隨空格的章節編號。

可以透過 添加垂直線\vrule。寬度可以透過關鍵字width:來配置\vrule width 1pt。高度和深度取決於行的高度和深度,並且可能因章節而異。恆定規則可用作$|$。後者的粗體版本用於以下範例:

\documentclass[svgnames]{book}

\usepackage{tikz}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}

\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}%
                  \ifx\chapterlabel\empty
                  \else
                    \chapterlabel $\boldsymbol{|}$ %
                  \fi
                  #1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\begin{document}
\tableofcontents
\chapter{Decision Trees}
Text
\chapter{Main}

\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference

\end{thebibliography}
\end{document}

第 3 頁:

第3頁

第 7 頁:

第7頁

相關內容