9

I found this script but couldn't manage to adjust it for parts. Here's what I got so far:

\documentclass{book}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}

\pagestyle{plain}

% background common settings
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}

% auxiliary counter
\newcounter{partshift}
\addtocounter{partshift}{-1}

\definecolor{mp}{RGB}{240,240,240}

\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{\Oldpart{#1}\pf\renewcommand{\parttitle}{#1}}

% the main command; the mandatory argument sets the color of the vertical box
\makeatletter
\newcommand\pf{%
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}
{\SetBgContents{%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=mp,inner sep=0pt,rectangle,text width=2cm,
    text height=4cm,align=center,anchor=north east] 
  at ($ (current page.north east) + (-0cm,-2*\thepartshift cm) $) 
  {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
    \raggedright\textcolor{black}{\parttitle}}}};
  \end{tikzpicture}}%
}
{\SetBgContents{%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=mp,inner sep=0pt,rectangle,text width=2cm,
    text height=4cm,align=center,anchor=north west] 
  at ($ (current page.north west) + (-0cm,-2*\thepartshift cm) $) 
  {\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
    \raggedright\textcolor{black}{\parttitle}}}};
  \end{tikzpicture}}
}
\bg@material}%
  \stepcounter{partshift}
}
\makeatother

\begin{document}

\part{A}
\chapter{a1}
\lipsum[1-7]

\part{B}
\chapter{b1}
\lipsum[1-7]

\part{C}
\chapter{c1}
\lipsum[1-7]

\end{document}
  • I think you should consider correcting the typo in this question before it is gatecrashed by excited hoards! – cfr Apr 15 '14 at 21:30
  • No party? damnit... – Moldevort Apr 15 '14 at 21:33
  • @cfr -- er, that's "hordes", no? but too bad about cancellation of party. – barbara beeton Apr 16 '14 at 8:47
7

Parts for thumbs

Update

The code below has been updated to use the new syntax for background. The updated syntax was provided by Gonzalo Medina to replace the code my original answer borrowed from this answer. See comments for history.

I am not certain how to adapt the code directly because \part works a bit differently from \chapter as I understand it. However, it is possible to combine parts of Gonzalo Medina's code with modified code from book.cls to achieve a similar effect:

\documentclass{book}
\usepackage[scale=1,angle=0,opacity=1]{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}

\backgroundsetup{contents={}}

\pagestyle{plain}

% auxiliary counter
\newcounter{partshift}
\addtocounter{partshift}{-1}

\definecolor{mp}{RGB}{240,240,240}

\newcommand{\parttitle}{}
\makeatletter
\def\@part[#1]#2{%
    \renewcommand\parttitle{#1}%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\pf%
      \centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\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*\thepartshift cm) $ )
        {\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\parttitle}}}};
    \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*\thepartshift cm) $)
      {\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\parttitle}}}};
      \end{tikzpicture}%
        }%
      }%
  }
  \BgMaterial}%
  \stepcounter{partshift}%
}

\begin{document}

\part{A}
\chapter{a1}
\lipsum[1-7]

\part{B}
\chapter{b1}
\lipsum[1-7]

\part{C}
\chapter{c1}
\lipsum[1-7]

\end{document}
| improve this answer | |
  • +1. Nice answer! I have a version using the new syntax for background (the syntax used in the linked post is old (although still functional)). Unfortunately is too long for a comment. Would you be interested in the code? Do you use the chat room? – Gonzalo Medina Apr 15 '14 at 23:46
  • @GonzaloMedina Thank you! Last time I tried, I could not 'chat' as the site would not recognise me as logged in. However, I discovered a couple of days ago that Meta now knows who I am and I can comment there and everything... so perhaps I can now chat, as well. I have always been able to eavesdrop, so I will see what you say even if I cannot reply. – cfr Apr 15 '14 at 23:56
  • 1
    The code is in a comment in the chat room: chat.stackexchange.com/transcript/message/14981596#14981596. – Gonzalo Medina Apr 16 '14 at 0:02
  • @GonzaloMedina Thanks! I tried to reply to you there but SE still claims that my browser doesn't support global authentication (even though it now works on Meta and other SE sites). It says about cookies and a modern browser (FF 28.0 should be modern enough!). Anyway, that works great if I remove the \pf commands from the body of the document. If not, I get weird results because the shift is done twice for parts B and C. Are you going to post an answer here? – cfr Apr 16 '14 at 0:21
  • 1
    OK, then I won't remove the comments. I am planning to update not just that answer but some others using the old syntax, but I still don't know when I'll do the changes. – Gonzalo Medina Apr 16 '14 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.