章のヘッダーにシンボルを追加する

章のヘッダーにシンボルを追加する

次のように、章のヘッダーに「|」記号または縦線を追加したいと思います。

元のコードは次のとおりです。

\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ページ

関連情報