1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| \documentclass{book}
\usepackage[scale=1,angle=0,opacity=1]{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\backgroundsetup{contents={}}
\pagestyle{plain}
% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
\definecolor{mp}{RGB}{240,240,240}
\newcommand{\chaptitle}{}
\makeatletter
\def\@chapter[#1]#2{
\renewcommand\chaptitle{#1}%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\pf%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
\makeatother
% the main command; the mandatory argument sets the color of the vertical box
\newcommand\pf{%
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}
{%
\backgroundsetup{%
contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
outer sep=0pt,
rectangle,
text width=2cm,
minimum height=4cm,
align=center,
anchor=north east,
]
at ( $ (current page.north east) + (0,-2*\thechapshift cm) $ )
{\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\chaptitle}}}};
\end{tikzpicture}%
}%
}%
}
{%
\backgroundsetup{%
contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
outer sep=0pt,
rectangle,
text width=2cm,
minimum height=4cm,
align=center,
anchor=north west,
]
at ($ (current page.north west) + (0,-2*\thechapshift cm) $)
{\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\chaptitle}}}};
\end{tikzpicture}%
}%
}%
}
\BgMaterial}%
\stepcounter{chapshift}%
}
\begin{document}
\chapter{a1}
\lipsum[1-7]
\chapter{b1}
\lipsum[1-7]
\chapter{c1}
\lipsum[1-7]
\end{document} |