fancyheaders 定义装饰

fancyheaders 定义装饰

我想将一些与章节名称中的装饰相关的代码添加到我喜欢的标题定义文件。

% Datei fancyheaders.tex
\usepackage{fancyhdr}   % Paket laden
\pagestyle{fancy}   % bereitgestelltes Layout 'fancy' laden

 \renewcommand{\chaptermark}[1]{\markboth{#1}{}}

  \makeatletter
  \def\@makechapterhead#1{%
   \vspace*{50\p@}%
   {\parindent \z@ \raggedright \normalfont
   %\ifnum \c@secnumdepth >\m@ne
    %    \huge\bfseries \@chapapp\space \thechapter
    %    \par\nobreak
    %    \vskip 20\p@
    %\fi
     \interlinepenalty\@M
      \Huge \bfseries #1\par\nobreak
     \vskip 40\p@
        }}
   \makeatother





\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{blindtext}

\newcommand{\chapnumfont}{%     % define font for chapter number
\usefont{T1}{pnc}{b}{n}%      % choose New Chancery, bold, normal shape
\fontsize{100}{100}%          % font size 100pt, baselineskip 100pt
\selectfont%                  % activate font
}
\colorlet{chapnumcol}{gray!100}  % color for chapter number

\titleformat{\chapter}[display]
{\filleft\bfseries}
{\filleft\chapnumfont\textcolor{chapnumcol}{\thechapter}}
{-24pt}
{\Huge}


\fancyhead{}
%\fancyhead[L]{\leftmark}
\fancyhead[L]{}
\fancyhead[R]{}%{\rightmark}
\fancyfoot{}
\fancyfoot[L]{}
\fancyfoot[C]{}%{\leftmark}
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}



% Style "plain" berschreiben, das bei 
%\chapter{...} mit aktiviert wird
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.4pt}}

并添加此代码(当放入章节文件时,它会破坏花哨的 hdr 设置)。希望将此代码添加到更高清晰度。

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\raggedleft}
{\begin{tikzpicture}
\node[text width=3cm,align=center] (chapnum)
 {\fontsize{100}{130}\color{gray}\selectfont\thechapter};%
\node[shift={(-1cm,10pt)},anchor=north west](CNW)
  at (chapnum.north west) {\pgfornament[width=1cm]{7}};
\node[shift={(1cm,10pt)},anchor=north east](CNE)
  at (chapnum.north east) {\pgfornament[width=1cm,symmetry=v]{7}};
\end{tikzpicture}
}
{0pt}
{\Huge}

感谢您的帮助。

答案1

也许这就是您想要实现的?

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{pgfornament}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\chapnumfont}{%     % define font for chapter number
\usefont{T1}{pnc}{b}{n}%      % choose New Chancery, bold, normal shape
\fontsize{100}{100}%          % font size 100pt, baselineskip 100pt
\selectfont%                  % activate font
}
\colorlet{chapnumcol}{gray!100}  % color for chapter number

\titleformat{\chapter}[display]
  {\normalfont\bfseries\filleft}
  {\begin{tikzpicture}
    \node[text width=3cm,align=center,inner sep=0pt] (chapnum)
       {\chapnumfont\color{chapnumcol}\thechapter};%
    \node[shift={(-1cm,0pt)},anchor=north west,inner sep=0pt](CNW)
      at (chapnum.north west) {\pgfornament[width=1cm]{7}};
    \node[shift={(1cm,0pt)},anchor=north east,inner sep=0pt](CNE)
      at (chapnum.north east) {\pgfornament[width=1cm,symmetry=v]{7}};
    \end{tikzpicture}%
  }
  {0pt}
  {\Huge}

\begin{document}

\setcounter{chapter}{1}% just for the example
\chapter{Title for a long test chapter}

\end{document}

在此处输入图片描述

我从原始代码中删除了与装饰品问题无关的部分;例如,与包装相关的部分fancyhdr。不要忘记将它们包含在您的实际文档中。

在评论中,有人要求为目录制作类似的设计;这可以使用键来完成\titleformatnumberless下面我展示了一种可能性(没有使用选项加载 titlesec explicit):

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{pgfornament}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\chapnumfont}{%     % define font for chapter number
\usefont{T1}{pnc}{b}{n}%      % choose New Chancery, bold, normal shape
\fontsize{100}{100}%          % font size 100pt, baselineskip 100pt
\selectfont%                  % activate font
}
\colorlet{chapnumcol}{gray!100}  % color for chapter number

\newcommand\MyOrnament[1]{%
  \makebox[3.8em][#1]{%
    \raisebox{.5\height}{\pgfornament[width=1cm]{7}}}%
}

\titleformat{\chapter}[display]
  {\normalfont\bfseries\filleft}
  {\begin{tikzpicture}
    \node[text width=3cm,align=center,inner sep=0pt] (chapnum)
       {\chapnumfont\color{chapnumcol}\thechapter};%
    \node[shift={(-1cm,0pt)},anchor=north west,inner sep=0pt](CNW)
      at (chapnum.north west) {\pgfornament[width=1cm]{7}};
    \node[shift={(1cm,0pt)},anchor=north east,inner sep=0pt](CNE)
      at (chapnum.north east) {\pgfornament[width=1cm,symmetry=v]{7}};
    \end{tikzpicture}%
  }
  {0pt}
  {\Huge#1}
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\bfseries\filleft}
  { }
  {0pt}
  {\MyOrnament{l}{\Huge#1}\MyOrnament{r}}

\begin{document}


\tableofcontents
\listoffigures
\setcounter{chapter}{1}% just for the example
\chapter{Title for a long test chapter}

\end{document}

生成的 ToC 的图像:

在此处输入图片描述

相关内容