使用无编号章节时,如何隐藏此自定义样式中的“第 0 章”?

使用无编号章节时,如何隐藏此自定义样式中的“第 0 章”?

当我使用时,一切都运行正常\chapter{chaptername},但我注意到我的目录和其他类似的未编号章节在标题中有一个“第 0 章”。

\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  \setcounter{definition}{0} % Reset Definition Counter  
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE CHAPTER \Huge\thechapter};
        \node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
              {\color{cyan}\Huge\MakeUppercase{#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }

我简单查了一下,但似乎无法理解如何使用条件来确定某些事情。

答案1

titlesec\ttl@labelfalse如果您调用,则设置\chapter*(否则为 true)。您可以使用它来插入包含章节标题的节点:

在此处输入图片描述

\documentclass{report}
\usepackage[explicit]{titlesec}% http://ctan.org/pkg/titlesec
\usepackage{tikz}% http://ctan.org/pkg/pgf
\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE CHAPTER \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
        \node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
              {\color{cyan}\Huge\MakeUppercase{#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\makeatother
\begin{document}
\tableofcontents
\chapter{A numbered chapter}
\chapter*{An unnumbered chapter}
\end{document}

\makeatletter注意和的定位\makeatother(在的定义之外\titleformat)。

相关内容