3

I would like to, temporarely, not assign new coloured boxes for some chapters. Is that possible, e.g. using or resetting the \ChapFrame command?

1 Answers1

4

I am assuming you are referring to the \ChapFrame command as given in this answer to Chapter Title in rotated vertical box at the margin. In that case, the answer is yes, you can conditionally activate/deactivate the frames. A little example:

\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}

enter image description here

I defined a boolean switch to activate/deactivate the frames; initially the boolean is true, so the frames are drawn. At any place where you want to deactivate the frames, use \Framefalse (possible preceded by a \clearpage). To activate the frames, simply use \Frametrue.

I also changed from the old syntax for the background package used in the linked answer to the newer syntax. Of course, the code with the old syntax can still be used.

Gonzalo Medina
  • 505,128
  • It seems that the background package and the draftwatermark packages somehow conflict; both a watermark from the draftwatermark package AND a 'draft' watermark, apparently arising due to the background package. Before making a MWE: is this a known problem? Also, a message 'Content=' is shown in the upper right corner of the compiled page. – User4536124 Mar 27 '14 at 13:06
  • @Stefan If you simply load both packages, you'll get the result described. Why are you loading both packages, anyway? – Gonzalo Medina Mar 27 '14 at 13:12
  • Because I, already, had: \usepackage{draftwatermark} \SetWatermarkText{\today\ \currenttime} \SetWatermarkLightness{0.85} \SetWatermarkScale{2} included... But I now see that the draftwatermark isn't the problem; this 'contents=' is still appearing in the upper left hand side of my pages – after invoking \ChapFrame. It disappears when I remove (all of) your proposed code. – User4536124 Mar 27 '14 at 14:08
  • @Stefan please open a fresh new question with a proper MWE illustrating the problem. (I ask you to do so because, as you see from my images, the bahviour you mention is not present with my answer). – Gonzalo Medina Mar 27 '14 at 18:57