在开发的代码中这里,我试图将它与一个花哨的标题一起使用。出于某种原因,“章节缩略图”代码无法按原计划工作。也就是说,章节缩略图不会按照章节的要求在页面上向下递增。
- 您能帮助我使此代码与花哨的“章节标题”配合使用吗?
- 另外,如何让普通章节(即附录之前的章节)的章节缩略图仅显示“第 1 章、第 2 章......”而不是章节名称?
以下是代码:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
%======================================================================================
% CHAPTER THUMB
%======================================================================================
\pagestyle{plain}
% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
%\ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}
ultramarine}
% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\newcommand\ChapterBox{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
text height=4cm,align=center,anchor=north east]
at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\parbox{4cm}{%
\centering\textcolor{white}{\scshape\leftmark}}}};
\end{tikzpicture}%
}
%======================================================================================
% PAGE HEADERS
%======================================================================================
\usepackage{etoolbox,fancyhdr} % Required for header and footer configuration
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark\ChapterBox} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark\ChapterBox} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\headrulecolor{blue!70}% Set header rule colour to 70% red.
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\footrulewidth}{.5pt} % Removes the rule in the footer
\cfoot[\fancyplain{}{}] {\fancyplain{}{\footnotesize\bfseries{Center Foot}}} \lfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Left Foot}}}
\rfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Right Foot}}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified
\fancypagestyle{plain}{%
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% No header rule
\renewcommand{\footrulewidth}{0pt}% No footer rule
}
% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\patchcmd{\@makechapterhead}
{\vskip 40\p@}
{\vskip 40\p@\stepcounter{chapshift}}{}{}
\makeatother
%======================================================================================
% CHAPTER HEADINGS
%======================================================================================
\usepackage{fourier}% change to lmodern if fourier is no available
\usepackage[explicit]{titlesec}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}
\renewcommand\thechapter{\arabic{chapter}}
\newcommand\chapnumfont{% font specification for the number
\fontsize{380}{130}\color{myblueii}\selectfont%
}
\newcommand\chapnamefont{% font specification for the name "PART"
\normalfont\color{white}\scshape\small\bfseries
}
\titleformat{\chapter}
{\normalfont\huge\filleft}
{}
{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\fill[myblueiii]
(current page.north west) rectangle ([yshift=-13cm]current page.north east);
\node[
fill=mybluei,
text width=2\paperwidth,
rounded corners=6cm,
text depth=18cm,
anchor=center,
inner sep=0pt] at (current page.north east) (chaptop)
{\thechapter};%
%{};%
\node[
anchor=south east,
inner sep=0pt,
outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
{\chapnumfont\thechapter};
%{};
\node[
anchor=south,
inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
%{\chapnamefont PROBLEM};
{};
\node[
anchor=north east,
align=right,
inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
{\parbox{.7\textwidth}{\raggedleft#1}};
\end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}
{\normalfont\huge\filleft}
{}
{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\fill[myblueiii]
(current page.north west) rectangle ([yshift=-13cm]current page.north east);
\node[
fill=mybluei,
text width=2\paperwidth,
rounded corners=6cm,
text depth=18cm,
anchor=center,
inner sep=0pt] at (current page.north east) (chaptop)
{};%
\node[
anchor=south east,minimum width=2in,
inner sep=0pt,
outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
{};
\node[
anchor=south,
inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
{};
\node[
anchor=north east,
align=right,
inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
{\parbox{.7\textwidth}{\raggedleft#1}};
\end{tikzpicture}%
}
\titlespacing*{\chapter}{0pt}{0pt}{3.5in}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{3.5in}
%======================================================================================
% MAINMATTER
%======================================================================================
\begin{document}
\part{Part One}
\mainmatter
\chapter{This is Where We Begin}
\lipsum[1-7]
\section{Test 1}
\lipsum[1-7]
\chapter{This is Some Middle Matter}
\lipsum[1-7]
\section{Test 2}
\lipsum[1-7]
\chapter{This is a Conclusion}
\lipsum[1-7]
\section{Test 3}
\lipsum[1-7]
\part{Part Two}
\appendix
\renewcommand\chaptermark[1]{\markboth{\sffamily\normalsize\bfseries \appendixname~\thechapter}{}}
\chapter{Appendix of stuff in A}
\lipsum[1-7]
\lipsum[1-7]
\chapter{Appendix of stuff in B}
\lipsum[1-7]
\lipsum[1-7]
\end{document}
答案1
由于您现在使用的是titlesec
,因此修补到\@makechapterhead
不会产生任何效果,并且移位尚未完成;您可以使用\tileformat
进行移位。要更改缩略图中的文本,请使用\@chapapp~\thechapter
而不是\leftmark
(这也将产生附录的预期结果):
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
%======================================================================================
% CHAPTER THUMB
%======================================================================================
\pagestyle{plain}
% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
%\ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}
ultramarine}
% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\makeatletter
\newcommand\ChapterBox{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
text height=4cm,align=center,anchor=north east]
at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\parbox{4cm}{%
\centering\textcolor{white}{\scshape\@chapapp~\thechapter}}}};
\end{tikzpicture}%
}
\makeatother
%======================================================================================
% PAGE HEADERS
%======================================================================================
\usepackage{etoolbox,fancyhdr} % Required for header and footer configuration
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{{\sffamily\normalsize\bfseries \ #1}}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{{\sffamily\normalsize\thesection\hspace{5pt}#1}}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark\ChapterBox} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark\ChapterBox} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\headrulecolor{blue!70}% Set header rule colour to 70% red.
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\footrulewidth}{.5pt} % Removes the rule in the footer
\cfoot[\fancyplain{}{}] {\fancyplain{}{\footnotesize\bfseries{Center Foot}}} \lfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Left Foot}}}
\rfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Right Foot}}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified
\fancypagestyle{plain}{%
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% No header rule
\renewcommand{\footrulewidth}{0pt}% No footer rule
}
% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\makeatother
%======================================================================================
% CHAPTER HEADINGS
%======================================================================================
\usepackage{fourier}% change to lmodern if fourier is no available
\usepackage[explicit]{titlesec}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}
\renewcommand\thechapter{\arabic{chapter}}
\newcommand\chapnumfont{% font specification for the number
\fontsize{380}{130}\color{myblueii}\selectfont%
}
\newcommand\chapnamefont{% font specification for the name "PART"
\normalfont\color{white}\scshape\small\bfseries
}
\titleformat{\chapter}
{\normalfont\huge\filleft}
{}
{0pt}
{\stepcounter{chapshift}%
\begin{tikzpicture}[remember picture,overlay]
\fill[myblueiii]
(current page.north west) rectangle ([yshift=-13cm]current page.north east);
\node[
fill=mybluei,
text width=2\paperwidth,
rounded corners=6cm,
text depth=18cm,
anchor=center,
inner sep=0pt] at (current page.north east) (chaptop)
{\thechapter};%
%{};%
\node[
anchor=south east,
inner sep=0pt,
outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
{\chapnumfont\thechapter};
%{};
\node[
anchor=south,
inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
%{\chapnamefont PROBLEM};
{};
\node[
anchor=north east,
align=right,
inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
{\parbox{.7\textwidth}{\raggedleft#1}};
\end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}
{\normalfont\huge\filleft}
{}
{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\fill[myblueiii]
(current page.north west) rectangle ([yshift=-13cm]current page.north east);
\node[
fill=mybluei,
text width=2\paperwidth,
rounded corners=6cm,
text depth=18cm,
anchor=center,
inner sep=0pt] at (current page.north east) (chaptop)
{};%
\node[
anchor=south east,minimum width=2in,
inner sep=0pt,
outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
{};
\node[
anchor=south,
inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
{};
\node[
anchor=north east,
align=right,
inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
{\parbox{.7\textwidth}{\raggedleft#1}};
\end{tikzpicture}%
}
\titlespacing*{\chapter}{0pt}{0pt}{3.5in}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{3.5in}
%======================================================================================
% MAINMATTER
%======================================================================================
\begin{document}
\part{Part One}
\mainmatter
\chapter{This is Where We Begin}
\lipsum[1-7]
\section{Test 1}
\lipsum[1-7]
\chapter{This is Some Middle Matter}
\lipsum[1-7]
\section{Test 2}
\lipsum[1-7]
\chapter{This is a Conclusion}
\lipsum[1-7]
\section{Test 3}
\lipsum[1-7]
\part{Part Two}
\appendix
\chapter{Appendix of stuff in A}
\lipsum[1-7]
\lipsum[1-7]
\chapter{Appendix of stuff in B}
\lipsum[1-7]
\lipsum[1-7]
\end{document}
结果: