如何检查它是章节还是章节*?

如何检查它是章节还是章节*?

我正在定制自己的章节,但是当我想测试它是否是时遇到了\chapter问题\chapter*

我不希望它在\chapter*应用时有一个点。

\titleformat{\chapter}{\sf\Huge\bf}{}{\dimexpr-\oddsidemargin-\hoffset-1in}
{%
\tikzstyle{background rectangle}=[fill=naranjaSaveTrack]%
\begin{tikzpicture}[framed]
\draw (0,0) node[anchor=east]{\color{black!70}\hspace{30pt}\thechapter.\hspace{5pt}#1};    
\end{tikzpicture}%
}

答案1

小手术\chapter

\documentclass{book}
\usepackage{titlesec,tikz,xcolor}
\usetikzlibrary{backgrounds}

\titleformat{\chapter}[display]
  {\Huge\sffamily\bfseries}
  {}
  {\dimexpr-\oddsidemargin-\hoffset-1in}
  {\chapterformat}

\newcommand\chapterprefix{%
  \ifchapterprefix
    \thechapter.\hspace{5pt}%
  \fi
}

\newif\ifchapterprefix
\makeatletter
\renewcommand\chapter{%
  \if@openright\cleardoublepage\else\clearpage\fi
  \thispagestyle{plain}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef{\chapterprefixtrue\@chapter}{\chapterprefixfalse\@schapter}}
\makeatother

\newcommand{\chapterformat}[1]{%
  \tikzstyle{background rectangle}=[fill=naranjaSaveTrack]%
  \begin{tikzpicture}[framed]
  \draw (0,0) node[anchor=east]{\color{black!70}\hspace{30pt}\chapterprefix#1};
  \end{tikzpicture}%
}

\colorlet{naranjaSaveTrack}{red!20} % or whatever you like

\begin{document}

\chapter*{Introduction}

\chapter{First}

\end{document}

在此处输入图片描述

相关内容