使用 tikz 包的章节样式

使用 tikz 包的章节样式

我找到了一个不错的章节标题样式的代码,我想使用它,如果可能的话,可以稍微修改一下。该代码使用包tikz和一个\begin{tikzpicture}...\end{tikzpicture}

代码运行正常,除了目录页面以更正常的标题样式呈现。问题似乎出在我使用的memoir类上,我需要能够使用多个包和重新定义。

代码运行正常目录标题使用例如report类。但正如预期的那样,它确实显示了许多“ Undefined control sequence”错误。

由于我对这种高级编码没有太多经验,我想问一下是否可以修改代码以便能够包含目录标题使用memoir类吗?

其次,我还想知道是否可以稍微修改一下代码,使章节号位于右侧,并且比章节标题稍大一些,并且以图像作为背景而不是浅蓝色?

下面是一个最小的工作文档,其中包括一些似乎不适用于报告类的代码。

\documentclass[svgnames,,a4paper,11pt,fleqn,fleqn,twoside,openany]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e,anyfontsize}

\usepackage{tikz}
\usepackage{verbatim}                       
\usepackage[explicit]{titlesec}
\usepackage[]{kpfonts}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}

\makepagestyle{Uni}                             % Defines page header and footer from here to ...
\makepsmarks{Uni}{%
    \createmark{chapter}{left}{shownumber}{}{. \ }
    \createmark{section}{right}{shownumber}{}{. \ }
    \createplainmark{toc}{both}{\contentsname}
    \createplainmark{lof}{both}{\listfigurename}
    \createplainmark{lot}{both}{\listtablename}
    \createplainmark{bib}{both}{\bibname}
    \createplainmark{index}{both}{\indexname}
    \createplainmark{glossary}{both}{\glossaryname}
}
\nouppercaseheads
\makeevenhead{Uni}{Gruppe Fib10, 1-15}{}{\leftmark}
\makeoddhead{Uni}{\rightmark}{}{Aalborg Universitet}
\makeevenfoot{Uni}{\thepage}{}{}
\makeoddfoot{Uni}{}{}{\thepage}
\makeheadrule{Uni}{\textwidth}{0.5pt}
\makefootrule{Uni}{\textwidth}{0.5pt}{1mm}

\copypagestyle{Unichap}{Uni}
\makeoddhead{Unichap}{}{}{}
\makeevenhead{Unichap}{}{}{}
\makeheadrule{Unichap}{\textwidth}{0pt}
\aliaspagestyle{chapter}{Unichap}
                                                % ... here


\newcommand*\chapterlabel{}                     % Chapter style from here to...
\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}      %  ... here


\begin{document}
\tableofcontents

\chapter{Introduction}
This is some text

\section{section}
This is some text

\chapter{Main}
\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference
\end{thebibliography}
\end{document}

答案1

该类memoir有一个用于排版所有内容的命令,这使得它非常可定制。 ToC(目录)由排版\printtoctitle(LoT 和 LoF 有类似的命令:\printlottitle和...你猜对了\printloftitle)。所有这些命令都接受一个参数,即包含列表名称的宏:\contentsname,,\listfigurename\listtablenamememoir手册中\tableofcontents,默认情况下,执行如下操作:

\tocheadstart
\printtoctitle{\contentsname}
\tocmark
\thispagestyle{chapter}
\aftertoctitle

因此,要实现新的风格,我们只需要\renewcommand{\printtoctitle}[1]{...}使用与章节相同的定义。

至于将标题移到左侧,这是一个简单的调整:将 改为anchor=westeast改为xshift=.9\paperwidth.1\paperwidth最后,要获得更大的章节编号,请使用\scalebox{<factor>}{\chapterlabel},而不仅仅是\chapterlabel,我使用了一个1.25因子,您可以将其更改为最适合您的任何值。

(不是这样的)我们:

\documentclass[svgnames,,a4paper,11pt,fleqn,fleqn,twoside,openany]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e,anyfontsize}

\usepackage{tikz}
\usepackage{verbatim}                       
\usepackage[explicit]{titlesec}
\usepackage[]{kpfonts}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}

\makepagestyle{Uni}                             % Defines page header and footer from here to ...
\makepsmarks{Uni}{%
    \createmark{chapter}{left}{shownumber}{}{. \ }
    \createmark{section}{right}{shownumber}{}{. \ }
    \createplainmark{toc}{both}{\contentsname}
    \createplainmark{lof}{both}{\listfigurename}
    \createplainmark{lot}{both}{\listtablename}
    \createplainmark{bib}{both}{\bibname}
    \createplainmark{index}{both}{\indexname}
    \createplainmark{glossary}{both}{\glossaryname}
}
\nouppercaseheads
\makeevenhead{Uni}{Gruppe Fib10, 1-15}{}{\leftmark}
\makeoddhead{Uni}{\rightmark}{}{Aalborg Universitet}
\makeevenfoot{Uni}{\thepage}{}{}
\makeoddfoot{Uni}{}{}{\thepage}
\makeheadrule{Uni}{\textwidth}{0.5pt}
\makefootrule{Uni}{\textwidth}{0.5pt}{1mm}

\copypagestyle{Unichap}{Uni}
\makeoddhead{Unichap}{}{}{}
\makeevenhead{Unichap}{}{}{}
\makeheadrule{Unichap}{\textwidth}{0pt}
\aliaspagestyle{chapter}{Unichap}
                                                % ... here


\newcommand*\chapterlabel{}                     % Chapter style from here to...
\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=west,xshift=.1\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\scalebox{1.25}{\chapterlabel}#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}      %  ... here
\renewcommand{\printtoctitle}[1]{%
\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=west,xshift=.1\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue, font=\normalfont\sffamily\Huge\bfseries\scshape\color{white}]
              {#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
}

\begin{document}
\tableofcontents

\chapter{Introduction}
This is some text

\section{section}
This is some text

\chapter{Main}
\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference
\end{thebibliography}
\end{document}

在此处输入图片描述

评论:最好使用memoir格式化章节标题(和所有其他部分)的方法,该机制经过深思熟虑。titlesec据我所知,该包适用于可定制性较低的类。

相关内容