
一時的に、いくつかの章に新しい色付きのボックスを割り当てないようにしたいと思います。\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}
フレームをアクティブ/非アクティブにするブール スイッチを定義しました。最初はブールが true なので、フレームが描画されます。フレームを非アクティブにする任意の場所で、 を使用します\Framefalse
(前に が付く場合もあります\clearpage
)。フレームをアクティブにするには、 を使用するだけです\Frametrue
。
また、リンクされた回答で使用されているパッケージの古い構文からbackground
新しい構文に変更しました。 もちろん、古い構文のコードも引き続き使用できます。