我想暂时不为某些章节分配新的彩色框。可以这样做吗?例如使用或重置命令\ChapFrame
?
答案1
我假设你指的\ChapFrame
是this answer
到章节标题位于边缘的旋转垂直框中。在这种情况下,答案是肯定的,您可以有条件地激活/停用框架。举个小例子:
\documentclass{book}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\pagestyle{plain}
\newif\ifFrame
\Frametrue
% background common settings
\backgroundsetup{
scale=1,
angle=0,
opacity=1,
contents={}
}
% 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}
% the main command; the mandatory argument sets the color of the vertical box
\newcommand\ChapFrame{%
\AddEverypageHook{%
\ifFrame
\ifthenelse{\isodd{\value{page}}}
{\backgroundsetup{contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=\BoxColor,
inner sep=0pt,
rectangle,
text width=2cm,
text height=4cm,
align=center,
anchor=north east
]
at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\hspace*{.3cm}%
\parbox[c][1.5cm][t]{3.4cm}{%
\raggedright\textcolor{black}{\scshape\leftmark}}}};
\end{tikzpicture}}}%
}
{\backgroundsetup{contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=\BoxColor,
inner sep=0pt,
rectangle,
text width=2cm,
text height=4cm,
align=center,
anchor=north west
]
at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\hspace*{.3cm}%
\parbox[c][1.5cm][t]{3.4cm}{%
\raggedright\textcolor{black}{\scshape\leftmark}}}};
\end{tikzpicture}}}
}
\BgMaterial%
\fi%
}%
\stepcounter{chapshift}
}
% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\begin{document}
\chapter[intro]{Introduction}
\ChapFrame
\lipsum[1-7]
\chapter{Results}
\ChapFrame
\lipsum[1-7]
\chapter{Discussion}
\Framefalse
\lipsum[1-7]
\chapter{Conclusion}
\Frametrue
\ChapFrame
\lipsum[1-7]
\end{document}
我定义了一个布尔开关来激活/停用框架;最初布尔值为真,因此绘制框架。在您想要停用框架的任何地方,使用\Framefalse
(可能前面带有\clearpage
)。要激活框架,只需使用\Frametrue
。
我还将链接答案中使用的包的旧语法更改为background
较新的语法。当然,使用旧语法的代码仍然可以使用。