从目录第一页的页眉中删除章节名称 - 第 2 部分

从目录第一页的页眉中删除章节名称 - 第 2 部分

这个问题是建立在解决方案发布在这里

例如,仅有的在目录页(如目录、图表列表等)的第一页上,我想从页眉中删除章节名称,以便目录、LOF 等的第一页看起来像这样:

在此处输入图片描述

但与目录、内容列表等相关的以下页面应在页眉中显示章节名称,如下所示:

在此处输入图片描述

以下是原始解决方案的代码:

\documentclass[11pt,openany]{book}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage[headheight=15pt]{geometry}
\patchcmd{\chapter}{\thispagestyle{plain}}{\pagestyle{fancy}}{}{}


\newif\ifchapterwidthstar
\newcommand\printchapternumber{\ifchapterwidthstar\else\thechapter\fi}
\makeatletter
\patchcmd\@chapter{\@afterheading}{\chapterwidthstarfalse\@afterheading}{}{}
\patchcmd\@schapter{\@afterheading}{\chapterwidthstartrue\@afterheading}{}{}
\makeatother
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \ifnum\value{chapter}=0
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries]  at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \end{tikzpicture}%
}

\title{A reasonably long title}
\date{\today}
\author{The author}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}

\begin{document}
\pagestyle{empty}
\maketitle

\tableofcontents
\listoffigures

\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]

\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument


\appendix
\chapter{Answer 1}
\lipsum[1]

\cleardoublepage
\chapter*{References}

\end{document}

答案1

很难相信这就是预期的结果,但这似乎就是你所要求的。

\documentclass[11pt,openany]{book}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage[headheight=15pt]{geometry}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{semifancy}\pagestyle{fancy}}{}{}

\newif\ifchapterwidthstar
\newcommand\printchapternumber{\ifchapterwidthstar\else\thechapter\fi}
\makeatletter
\patchcmd\@chapter{\@afterheading}{\chapterwidthstarfalse\@afterheading}{}{}
\patchcmd\@schapter{\@afterheading}{\chapterwidthstartrue\@afterheading}{}{}
\makeatother
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \ifnum\value{chapter}=0
    \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries]  at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
    \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
    \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \end{tikzpicture}%
}
\fancyfoot[CE]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
  \end{tikzpicture}%
}
\fancyfoot[CO]{
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large\bfseries, minimum size=.5in] at (current page.south east) {\thepage};
  \end{tikzpicture}%
}
\fancypagestyle{semifancy}{%
  \pagestyle{fancy}%
  \fancyhead[E]{%
    \begin{tikzpicture}[overlay, remember picture]%
      \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
      \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
      \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
    \end{tikzpicture}%
  }%
  \fancyhead[O]{%
    \begin{tikzpicture}[overlay, remember picture]%
      \fill[gmitblue] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
      \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
      \ifnum\value{chapter}=0
      \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\printchapternumber};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
      \fi
      \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
    \end{tikzpicture}%
  }%
}

\title{A reasonably long title}
\date{\today}
\author{The author}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}

\begin{document}
\pagestyle{empty}
\maketitle

\tableofcontents
\listoffigures

\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]

\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument

\appendix
\chapter{Answer 1}
\lipsum[1]

\cleardoublepage
\chapter*{References}

\end{document}

可能不受欢迎,但是谁知道呢?

为什么TOPIC TO BE DISCUSSED定义中要硬编码?为什么内容会覆盖徽标?

除此之外,我觉得布局非常混乱,因为我根本无法轻易分辨出一章在哪里结束,下一章在哪里开始。它看起来越来越像一模一样。

相关内容