10

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}
Moldevort
  • 1,295

1 Answers1

8

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}
cfr
  • 198,882
  • +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: http://chat.stackexchange.com/transcript/message/14981596#14981596. – Gonzalo Medina Apr 16 '14 at 00: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 00:21
  • Ah; those \pf commands! A remanant from the tests. No; I won't add an answer here, if you want to, you can take the parts of the code in chat that you consider useful. I think it is a good idea to use the new syntax for the package. Of course, that is just a suggestion; if you don't want to modify your answer, let me know. – Gonzalo Medina Apr 16 '14 at 00:27
  • @GonzaloMedina Done. Thank you. I posted my very slightly amended version. – cfr Apr 16 '14 at 00:37
  • Great! By the way, no need to mention me in your answer :) I'll delete my comments shortly. – Gonzalo Medina Apr 16 '14 at 00:45
  • @GonzaloMedina Hmmm. That would feel dishonest. Are you going to update the code in the answer I linked to? Then linking that would attribute the relevant parts of the code to you, I think, as in my original answer. – cfr Apr 16 '14 at 01:11
  • 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 01:15