1

in the code given below for placing a chapter thumb, I wanted to modify the simple rectangular box to give this as the new chapter thumb:

enter image description here

Here is the code that I have so far:

CODE

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{geometry}
\usepackage{atveryend}%%%% <--- !
\usepackage{etoolbox,fancyhdr}
\usepackage{fourier}

\usetikzlibrary{calc}

\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{line}{RGB}{70,160,216}
\definecolor{fillh}{RGB}{225,233,251}

\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}

%======================================================================================
%   CHAPTER THUMB
%======================================================================================
\def\subsectiontitle{}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
\renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}


\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}
\tikzset{every picture/.style={remember picture}}
\pagestyle{plain}

% 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}
  ultramarine}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}
\fancyhead[E]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south west, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\thepage};
    \node[anchor=south west, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south east) {\thechapter};
    \node[anchor=south west] at (chapter.south east) {\leftmark};
    \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north east]
  at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
   \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
\end{tikzpicture}
}%

\fancyhead[O]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[align=right, anchor=south east, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\thepage};
    \node[align=right, anchor=south east, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south west) {\thechapter};
    \node[align=right, anchor=south east] at (chapter.south west) {\leftmark};
      \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north west]
  at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
\end{tikzpicture}
}
\fancyfoot[CE]{}
\fancyfoot[CO]{}
\setlength{\headheight}{12pt}


\usepackage[height={2cm},distance={2mm},topthumbmargin={auto},bottomthumbmargin={auto}]{thumbs}%%%% <--- !


\begin{document}
\pagenumbering{arabic}%%%% <--- !
\chapter{Problems}
\addthumb{\thechapter}{\Large{\thechapter}}{white}{mybluei}%%%% <--- !
\section{Problem 1}
\subsection{Problem 1}
\lipsum[1]
\subsection{Solution 1}
\lipsum[1-7]
\cleardoublepage

\appendix
\chapter{Appendix \thechapter}
\addthumb{\thechapter}{\Large{\thechapter}}{white}{mybluei}%%%% <--- !
\lipsum[1-20]

\end{document} 
1
+50

Here is a solution (edited) using the thumbs package, as requested in the comments. I removed my old solution because I think the advanced behaviour of the thumbs package is essentially always preferable.

Apologies I started from scratch as I wasn't sure what all in your MWE was actually needed.

Overview

  • To obtain the graphic, we overwrite the \rule within \th@mbprint command using \patchcmd from etoolbox
  • We use the length \th@mbposyA from thumbs package and \paperheight to determine the length of the lines
  • We append to \chaptermark to store the chapter title in \chap@title, which we then rotate in a protected group \chaptitle
  • We also use \apptocmd from etoolbox to call \addthumb after every \chapter

MWE

\documentclass{book}
\usepackage[a6paper]{geometry} % demo only
\usepackage{lipsum}            % demo only
% <solution>
\usepackage[width=1cm,height=3cm,distance=2mm]{thumbs} % for thumbs
\usepackage{etoolbox}   % fot patching
\usepackage{tikz}       % for drawing
\usetikzlibrary{arrows} % for "-o"
\definecolor{mybluei}{RGB}{0,173,239}
\makeatletter
\newcommand{\fancyrule}[2]{%
%  \rule{#1}{#2} % DEBUG: original thumbs behaviour
  \ifodd\c@CurrentPage\def\sign{+}\else\def\sign{-}\fi % flip stuff
  \begin{tikzpicture}
    \useasboundingbox (0,0) rectangle ++ (#1,#2); % same placement
    \fill[\th@mbbackgroundcolourA] % color block
         (#1,#2) rectangle
         (0,0) --
      ++ (+0.5#1,-0.5#1) --
      ++ (+0.5#1,+0.5#1);
    \draw[\th@mbbackgroundcolourA,ultra thick,-o] % middle line
         (0.5#1,#2) --
      ++ (0,\th@mbposyA-#2-\paperheight+2#1) --
      ++ (\sign1.5#1,-1.5#1);
    \draw[\th@mbbackgroundcolourA,ultra thick,-o] % inner line
         (0.5#1\sign0.5#1,#2) --
      ++ (0,\th@mbposyA-#2-\paperheight+2.212#1) --
      ++ (\sign1.0#1,-1.0#1);
%    \draw[red,dashed] (0,0) rectangle (#1,#2); % DEBUG: same as original
  \end{tikzpicture}
}
\patchcmd{\th@mbprint}{\rule}{\fancyrule}{}{} % patch the "rule"
\newcommand{\chaptitle}{% for rotating the thumbs content
  \ifodd\c@CurrentPage\def\sign{-}\else\def\sign{+}\fi
  \rotatebox{\sign90}{\chap@title}
}
\let\ochaptermark\chaptermark % for storing the chapter title
\def\chaptermark#1{\def\chap@title{#1}\ochaptermark{#1}}
\apptocmd{\@chapter}{% add thumb after every chapter command
  \addthumb{\thechapter}{\sffamily \protect\chaptitle}{white}{mybluei}
}{}{}
\makeatother
% </solution>
\begin{document}
  \pagenumbering{arabic}
  \chapter{Problems}
  \lipsum[1-2]
  \section{Hard Ones}
  \lipsum[3-4]
  \cleardoublepage
  \chapter{Solutions}
  \lipsum[1-2]
  \appendix
  \chapter{Miscellaneous}
  \lipsum[1-2]
\end{document}

Output

(a6paper is very small so we can see multiple pages)

enter image description here

6
  • 1
    But your code doesn't shift the thumbs at the beginning of each new chapter. Isn't this the actual intention of thumbs? Not to mention the case when the thumbs reach the bottom of the page and have to jump to the top again. All those cases are handled by thumbs.sty. Oct 21 '20 at 14:53
  • 1
    Fair point. I missed the thumbs package loading here. It's possible to move the thumbs down incrementally in my solution using \thechapter and yshift, but a) it won't wrap, and b) it breaks after \appendix since \thechapter becomes a letter. I wasn't 100% clear what the OP was asking TBH. Oct 21 '20 at 15:22
  • 1
    It seems the thumbs package only supports rectangular blocks. Let me look at the implementation to see if there's a hook we can use. Oct 21 '20 at 22:54
  • 1
    @jessexknight A hook could be \th@mbprint. But expansion is so weird there that this is no fun... Oct 21 '20 at 23:16
  • 1
    @Joe Please see the revised solution which uses the thumbs package now. Thanks for your input Andreas! Oct 22 '20 at 23:45
1

Here is an extended version that shifts and wraps around. It's based on the example of @jessexknight.

\documentclass{book}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{math}

\makeatletter
\newlength\ctw % half width
\newlength\cth % height
\newlength\ctx % x-offset
\newlength\ctf
\newlength\cttopmargin % top margin of first thumb
\newlength\ct@top % current top
\setlength\ct@top{\paperheight}

\newcommand\my@thumb{}
\newcommand\thumb[1]{%
  \def\my@thumb{\sffamily\normalsize\bfseries #1}%
  \addtolength\ct@top{\cth}% old \cth
  \settowidth\cth{\my@thumb}% new \cth
  \addtolength\cth{20pt}% label margin
  \ifdim \dimexpr\ct@top+\cth\relax > \dimexpr\paperheight-6\ctw\relax
    \setlength\ct@top\cttopmargin
  \fi
}

\newcommand\nothumbs{\def\my@thumb{}}
\nothumbs

\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \ifodd\c@page
      \setlength\ctx{\paperwidth}%
      \setlength\ctf{+1\ctw}%
    \else
      \setlength\ctx{0in}%
      \setlength\ctf{-1\ctw}%
    \fi
    \ifx\@empty\my@thumb\else  
    \begin{tikzpicture}[overlay,xshift=\ctx]
      \tikzmath{%
        \ct@top@ = \ct@top / -1cm;
        \ct@ht = \cth / 1cm;
        \ct@label = \ct@top@ - \ct@ht / 2;
      }%
      \fill[thumb] (0,\ct@top@) rectangle
            ++ (-2\ctf,-1\cth)
         -- ++ (+1\ctf,-1\ctw)
         -- ++ (+1\ctf,+1\ctw);
      \draw[thumb,ultra thick,-o] (-1\ctf,\ct@top@)
         -- (-1\ctf,-\paperheight+4\ctw)
         -- ++ (-3\ctf,-3\ctw);
      \draw[thumb,ultra thick,-o] (-2\ctf,\ct@top@)
         -- (-2\ctf,-\paperheight+4.414\ctw)
         -- ++ (-2\ctf,-2\ctw);
      \node[white] at (-\ctf,\ct@label) {\rotatebox{90}{\my@thumb}};
    \end{tikzpicture}%
    \fi
  }}
\makeatother

%
% user interface
%
\setlength\ctw{0.2in}% half width of thumb
\setlength\cttopmargin{20mm}% top margin of first thumb
\definecolor{thumb}{RGB}{0,173,239}% color of thumb

% set thumb with: \thumb{foobar}
% stop thumbs with: \nothumbs


\begin{document}
\chapter{No thumbs here}\lipsum[1-6]
\chapter{XXX 1}\thumb{Lorem ipsum}\lipsum[1-6]
\chapter{XXX 2}\thumb{Dolor}\lipsum[1-6]
\chapter{XXX 3}\thumb{Sit a met consectetuer}\lipsum[1-6]
\chapter{XXX 4}\thumb{Adipiscing elit}\lipsum[1-6]
\chapter{XXX 5}\thumb{Ut purus elit vestibulum ut}\lipsum[1-6]
\chapter{XXX 6}\thumb{Nunc eleifend consequat lorem}\lipsum[1-6]
\chapter{XXX 7}\thumb{Molestie vitae placerat}\lipsum[1-6]
\chapter{XXX 8}\thumb{Tortor gravida sapien}\lipsum[1-6]
\appendix
\chapter{AAA 1}\thumb{Phasellus eu tellu}\lipsum[1-6]
\chapter{AAA 2}\thumb{Praesent eget sem vel leo}\lipsum[1-6]
\chapter{Again no thumbs}\nothumbs\lipsum[1-6]
\end{document}

enter image description here

0

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.