標題格式問題:不希望章節樣式適用於目錄和參考書目

標題格式問題:不希望章節樣式適用於目錄和參考書目

請考慮以下程式碼:

\documentclass[11pt,twoside,openany]{book}

\usepackage[svgnames,x11names]{xcolor}
\usepackage{wallpaper}
\usepackage{changepage}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\usepackage{lipsum}
\usepackage{geometry}
\geometry{
   paperwidth=216mm, paperheight=303mm,
   left=23mm,  %% or inner=23mm
   right=18mm, %% or outer=18mm
   top=23mm, bottom=23mm,
   headheight=\baselineskip,
   headsep=7mm,
   footskip=7mm
}


%% Command to hold chapter illustration image
\newcommand\chapterillustration{}

%% Define how the chapter title is printed
\titleformat{\chapter}{}{}{0pt}{
%% Background image at top of page
\ThisULCornerWallPaper{1}{\chapterillustration}
%% Draw a semi-transparent rectangle across the top
\tikz[overlay,remember picture]
  \fill[LightSalmon1,opacity=.7]
  (current page.north west) rectangle 
  ([yshift=-3cm] current page.north east);
  %% Check if on an odd or even page
  \checkoddpage\strictpagecheck
  %% On odd pages, "logo" image at lower right
  %% corner; Chapter number printed near spine
  %% edge (near the left); chapter title printed
  %% near outer edge (near the right).
  \ifoddpage{
    \ThisLRCornerWallPaper{.35}{fern_mo_01}
    \begin{tikzpicture}[overlay,remember picture]
    \node[anchor=south west,
      xshift=20mm,yshift=-30mm,
      font=\sffamily\bfseries\huge] 
      at (current page.north west) 
      {\chaptername\ \thechapter};
    \node[fill=Sienna!80!black,text=white,
      font=\Huge\bfseries, 
      inner ysep=12pt, inner xsep=20pt,
      rounded rectangle,anchor=east, 
      xshift=-20mm,yshift=-30mm] 
      at (current page.north east) {#1};
    \end{tikzpicture}
  }
  %% On even pages, "logo" image at lower left
  %% corner; Chapter number printed near outer
  %% edge (near the right); chapter title printed
  %% near spine edge (near the left).
  \else {
    \ThisLLCornerWallPaper{.35}{fern_mo_01}
    \begin{tikzpicture}[overlay,remember picture]
    \node[anchor=south east,
      xshift=-20mm,yshift=-30mm,
      font=\sffamily\bfseries\huge] 
      at (current page.north east)
      {\chaptername\ \thechapter};
    \node[fill=Sienna!80!black,text=white,
      font=\Huge\bfseries,
      inner sep=12pt, inner xsep=20pt,
      rounded rectangle,anchor=west,
      xshift=20mm,yshift=-30mm] 
      at ( current page.north west) {#1};
    \end{tikzpicture}
  }
  \fi
}
\titlespacing*{\chapter}{0pt}{0pt}{135mm}


\begin{document}
\tableofcontents

\renewcommand\chapterillustration{six-computers-chips-circuits}
\newpage
\chapter{Hello World!}


\renewcommand\chapterillustration{cherry-tomatos}
\newpage
\chapter{Whassup, Doc?}

\end{document}

問題:

我應用於“章節”的精美設定適用於文件中的所有內容。 => 目錄和參考書目(不包含在上面的範例程式碼中)現在顯示為「章節」。

另外,我必須禁用:

%\listoffigures
%\listoftables

因為啟用這些部分會導致編譯錯誤(當章節設定適用於它們時)。

請幫我找一些方法來避免這個問題。

答案1

由於目錄位於編號章節之前,因此您可以將\titleformat\titlespacing命令移到之後\tableofcontents,這樣就不會受到影響。

您還可以定義命令,其作用就像一個開關:一個\titleformat\titlesection奇特的方式調用它,另一個以預設設定調用它,這可以在titlesec文件附錄中找到。因此,您可以根據需要打開或關閉。

這是一個切換樣式的小範例,可以作為您的開始 - 只是更改顏色:

\documentclass{book}
\usepackage{color}
\usepackage{titlesec}
\newcommand*{\fancychapterstyle}{%
  \titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\color{blue}}{\chaptertitlename\ \thechapter}
  {20pt}{\Huge\color{blue}}
  \titlespacing*{\chapter}{0pt}{50pt}{40pt}
}
\newcommand*{\standardchapterstyle}{%
  \titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
  \titlespacing*{\chapter}{0pt}{50pt}{40pt}
}
\begin{document}
\tableofcontents
\fancychapterstyle
\chapter{One}
\standardchapterstyle
\begin{thebibliography}{99}
\end{thebibliography}
\end{document}

相關內容