在下面的 MWE 代码中:
我该如何从
\rightmark
标题中删除章节编号,从页脚中删除“第十章”,并且
将正文向下移动,使其不与标题图像重叠。
从未编号的章节(例如图表、目录等)中删除“0”。
以下是按照以下代码修改的代码这里给出的解决方案:
\documentclass[11pt]{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}
\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}
\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);
\node[anchor=south west, text width=1cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\textbf{\thechapter}};
\node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont] (chapter) at (oddpagenum.south east) {\quad\textbf{TOPIC TO BE DISCUSSED}};
\node[anchor=north east, minimum size=1in, inner xsep=5mm] at (current page.north east) {\includegraphics[scale=.4]{example-image-a}};
% \node[anchor=south west] at (chapter.south east) {\leftmark};
\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[align=right, anchor=south east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\textbf{\rightmark}};
% \node[align=right, anchor=south east, text width=1.5cm, text=white, font=\fontsize{.5cm}{5.5cm}\selectfont] (leftmark) at (evenpagenum.south west) {\rightmark};
\node[anchor=north west, minimum size=1in, inner xsep=5mm] at (current page.north west) {\includegraphics[scale=.4]{example-image-b}};
% \node[align=right, anchor=south east] at (chapter.south west) {\leftmark};
\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, minimum size=.5in] at (current page.south west) {\textbf{\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, minimum size=.5in] at (current page.south east) {\textbf{\thepage}};
\end{tikzpicture}
}
\setlength{\headheight}{12pt}
\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}
\maketitle
\tableofcontents
\listoffigures
\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]
\section{Solution 1}
\lipsum
\lipsum
\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]
\section{Solution 2}
\lipsum[1-5]
\appendix
\chapter{Appendix A}
\lipsum[1-5]
\end{document}
答案1
这是另一个解决方案:
问题 1 和 2:
您必须定义填充标记的命令。通常,章节和节号用于标记。因此,您必须重新定义代码以不使用这些代码。这在 fancyhdr 手册中有描述。将
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
后 \pagestyle{fancy}
问题3:
您必须在标题和文本之间留出更多空间。这是由 定义的headsep
。使用此“几何”行:
\usepackage[a4paper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm,
includehead, headheight=14pt, headsep=10mm]{geometry}
然后移除\setlength{\headheight}{12pt}
(反正它太小了)。让几何来完成工作。
根据您的喜好调整 10mm。
问题4:
这是我的解决方案。
替换为。\thechapter
\fancyhead[O]
\mychapter
在序言中(之前\begin{document}
):
\newcommand{\mychapter}{}
第一章之前:
\newpage
\renewcommand{\mychapter}{\thechapter}
答案2
这个答案
消除了您在问题中没有提到的由您的代码引起的很多坏框;
geometry
避免在背后定义自己不知道的事情而造成混乱;避免内容与页眉重叠;
删除等于零的章节号并
\rightmark
在这些情况下重复;引入了一个新的坏框,这不是页面样式的结果,而只是当前虚拟内容的一个功能,因此在这一点上并不值得费心去消除。
它没有回答您的其他杂项问题。当您每个问题只问一个问题时,网站效果最佳,而对我来说,一个问题太多了。如果我以后有时间,我可能会回过头来回答它,但其他问题与我在这里所做的事情无关,最好由熟悉的人来回答,titleps
他们可以向您展示如何使用它来代替fancyhdr
。与此同时,我建议寻找那种解决方案。我不喜欢 ,titleps
因为我对 过敏titlesec
。所以我几乎总是使用fancyhdr
。但如果您已经在使用titlesec
,则大概您不会同样过敏,最好使用为其设计的页面样式。
请注意,问题在于您没有一致地使用 LaTeX 标记中的信息。相反,您\thechapter
明确地说明了这一点,当章节没有编号时,这显然行不通。解决此问题的一种方法是对前言、正文和后文使用不同的页面样式。(您没有使用这些命令 - 我不知道这是因为您不想要传统的分页还是出于其他原因。)
无论如何,这里有一个解决页面样式相关的坏框、零章节和重叠内容的解决方案。
\documentclass[11pt,a4paper]{book}
\usepackage{calc}
\usepackage[left=1.5cm, right=1.5cm, bindingoffset=1.5cm, headheight=120pt, top={120pt+10mm}]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}
\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}
\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)$) {\thechapter};
\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) {\includegraphics[height=120pt]{example-image-a}};
\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) {\includegraphics[height=120pt]{example-image-b}};
\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}%
}
\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}
\maketitle
\tableofcontents
\listoffigures
\chapter{Problem 1}
\section{Problem 1}
\lipsum[1]
\section{Solution 1}
\lipsum
\lipsum
\chapter{Problem 2}
\section{Problem 2}
\lipsum[1]
\section{Solution 2}
\lipsum[1-5]
\appendix
\chapter{Appendix A}
\lipsum[1-5]
\end{document}