2

I would like to use a different shape than a rectangle as chapterthumb-symbol, i.e. a circle or a diamond with rounded corners. Is this possible at all using scrlayer-scrpage and a two-sided scrreprt setup? I saw that one can draw shapes in LaTeX using Tikz, how could I implement this with the setup I have?

MWE:

\documentclass[11pt, twoside, openright, BCOR=1cm, headsepline]{scrreprt}
\usepackage[paperheight=24cm, paperwidth=17cm, inner=2.3cm, outer=1.6cm, top=2.5cm, bottom=1.9cm,footskip=1cm]{geometry}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}


\usepackage{graphicx}
\usepackage{xcolor}

%%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

%%--"Chapter #" in lehead (only for numbered chapters), chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\ofoot[\pagemark]{\pagemark}

\renewcommand\chapterpagestyle{empty} %% no header or page numbers on chapter title pages


%%%---thumb indices using chapterthumb

% the following bases on an example in the KOMA-Script book:
\newcommand*{\firstchapterthumbskip}{.1\paperheight}
\newcommand*{\lastchapterthumbskip}{\firstchapterthumbskip}
\newcommand*{\chapterthumbheight}{2em}
\newcommand*{\chapterthumbwidth}{.1\paperheight}
\newcommand*{\chapterthumbskip}{.1\paperheight}
\newcommand*{\chapterthumbboxcolor}{gray!30}
\newcommand*{\chapterthumbcolor}{white}
\newcommand*{\chapterthumbformat}{\thechapter}
\newkomafont{chapterthumb}{\normalfont\Large\color{\chapterthumbcolor}}

\makeatletter
\newcommand*\chapterthumb@box{%
    \parbox[c][\chapterthumbheight][c]{\chapterthumbwidth}{%
        \centering\usekomafont{chapterthumb}{\chapterthumbformat}%
    }%
}
\newcommand*{\chapterthumbbox}{%
    \if@mainmatter
    \ifnum\value{chapter}>\z@
    \ifnum \value{chapterthumb}<\z@
    \else
    \begingroup
    \protected@edef\reserved@a{\chapterthumbformat}%
    \ifx\reserved@a\lastchapterthumbformat\else
    \stepcounter{chapterthumb}%
    \global\let\lastchapterthumbformat\reserved@a
    \fi
    \@tempcnta=\numexpr 
    \dimexpr 
    \paperheight
    -\firstchapterthumbskip
    -\chapterthumbwidth
    -\lastchapterthumbskip
    \relax / \dimexpr 
    \chapterthumbskip 
    \relax
    +1
    \relax
    \ifnum \value{chapterthumb}<\@tempcnta
    \else
    \setcounter{chapterthumb}{0}%
    \fi
    \vspace*{%
        \dimexpr 
        \firstchapterthumbskip
        + ( \chapterthumbskip )
        * \value{chapterthumb}%
        - \baselineskip
        \relax
    }\par
    \setlength{\fboxsep}{0pt}%
    \ifodd\value{page}
    \hfill
    \makebox[0pt][r]{%
        \rotatebox[origin=tr]{90}{%
            \colorbox{\chapterthumbboxcolor}{%
                \parbox[t][\chapterthumbheight]{\chapterthumbwidth}{%
                    \chapterthumb@box
                    \vskip3mm
    }}}}%
    \else
    \hspace*{-3mm}%
    \makebox[0pt][l]{%
        \rotatebox[origin=tr]{90}{%
            \colorbox{\chapterthumbboxcolor}{%
                \parbox{\chapterthumbwidth}{%
                    \vskip3mm
                    \chapterthumb@box
    }}}}%
    \fi
    \endgroup
    \fi
    \fi
    \fi
}
\makeatother

\newcounter{chapterthumb}
\setcounter{chapterthumb}{10000}
\newcommand*{\lastchapterthumbformat}{\relax}

\DeclareNewLayer[%
background,%
outermargin,%
contents=\chapterthumbbox
]{chapterthumb}

\newcommand*\EnableChapterthumb{%
    \IfLayerAtPageStyle{scrheadings}{chapterthumb}{}
    {\AddLayersToPageStyle{@everystyle@}{chapterthumb}}%
}
\newcommand*\DisableChapterthumb{%
    \RemoveLayersFromPageStyle{@everystyle@}{chapterthumb}%
}

\EnableChapterthumb

\usepackage{lipsum}


\begin{document}

\chapter{First}

\lipsum[1-6]

\chapter{Second}

\lipsum[7-12]

\end{document}

1 Answer 1

3

It would appear to be possible.

\documentclass[11pt, twoside, openright, BCOR=1cm, headsepline]{scrreprt}
\usepackage[paperheight=24cm, paperwidth=17cm, inner=2.3cm, outer=1.6cm, top=2.5cm, bottom=1.9cm,footskip=1cm]{geometry}
\usepackage{tikz}

%%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

%%--"Chapter #" in lehead (only for numbered chapters), chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\ofoot[\pagemark]{\pagemark}

\renewcommand\chapterpagestyle{empty} %% no header or page numbers on chapter title pages


%%%---thumb indices using chapterthumb

% the following bases on an example in the KOMA-Script book:
\newcommand*{\firstchapterthumbskip}{.1\paperheight}
\newcommand*{\lastchapterthumbskip}{\firstchapterthumbskip}
\newcommand*{\chapterthumbheight}{3em}
\newcommand*{\chapterthumbwidth}{.1\paperheight}
\newcommand*{\chapterthumbskip}{.1\paperheight}
\colorlet{chapterthumbboxcolor}{gray!30}
\newcommand*{\chapterthumbcolor}{white}
\newcommand*{\chapterthumbformat}{\thechapter}
\newkomafont{chapterthumb}{\normalfont\Large\color{\chapterthumbcolor}}

\makeatletter
\newcommand*\chapterthumb@box{%
  \usekomafont{chapterthumb}%
    \parbox[c][\chapterthumbheight][c]{\chapterthumbwidth}{%
      \centering
      \begin{tikzpicture}
        \node[circle, inner sep=1.3ex, fill=chapterthumbboxcolor]
          {\chapterthumbformat};
      \end{tikzpicture}%
    }%
}
\newcommand*{\chapterthumbbox}{%
    \if@mainmatter
    \ifnum\value{chapter}>\z@
    \ifnum \value{chapterthumb}<\z@
    \else
    \begingroup
    \protected@edef\reserved@a{\chapterthumbformat}%
    \ifx\reserved@a\lastchapterthumbformat\else
    \stepcounter{chapterthumb}%
    \global\let\lastchapterthumbformat\reserved@a
    \fi
    \@tempcnta=\numexpr
    \dimexpr
    \paperheight
    -\firstchapterthumbskip
    -\chapterthumbwidth
    -\lastchapterthumbskip
    \relax / \dimexpr
    \chapterthumbskip
    \relax
    +1
    \relax
    \ifnum \value{chapterthumb}<\@tempcnta
    \else
    \setcounter{chapterthumb}{0}%
    \fi
    \vspace*{%
        \dimexpr
        \firstchapterthumbskip
        + ( \chapterthumbskip )
        * \value{chapterthumb}%
        - \baselineskip
        \relax
    }\par
    \setlength{\fboxsep}{0pt}%
    \ifodd\value{page}
    \hfill
    \makebox[0pt][r]{%
        \rotatebox[origin=c]{90}{\chapterthumb@box}}%
    \else
    \makebox[0pt][l]{%
        \rotatebox[origin=c]{90}{\chapterthumb@box}}%
    \fi
    \endgroup
    \fi
    \fi
    \fi
}
\makeatother

\newcounter{chapterthumb}
\setcounter{chapterthumb}{10000}
\newcommand*{\lastchapterthumbformat}{\relax}

\DeclareNewLayer[%
background,%
outermargin,%
contents=\chapterthumbbox
]{chapterthumb}

\newcommand*\EnableChapterthumb{%
    \IfLayerAtPageStyle{scrheadings}{chapterthumb}{}
    {\AddLayersToPageStyle{@everystyle@}{chapterthumb}}%
}
\newcommand*\DisableChapterthumb{%
    \RemoveLayersFromPageStyle{@everystyle@}{chapterthumb}%
}

\EnableChapterthumb

\usepackage{lipsum}

\begin{document}

\chapter{First}

\lipsum[1-6]

\chapter{Second}

\lipsum[7-12]

\end{document}

enter image description here

If you want diamonds with rounded corners, add \usetikzlibrary{backgrounds} after \usepackage{tikz} and replace the \begin{tikzpicture} ... \end{tikzpicture}% part with something like this:

\begin{tikzpicture}
  \node[inner sep=2.5ex] (n) {\chapterthumbformat};
  \begin{scope}[on background layer]
    \path[fill=chapterthumbboxcolor, rounded corners=2pt]
      (n.north) -- (n.west) -- (n.south) -- (n.east) -- cycle;
  \end{scope}
\end{tikzpicture}%

enter image description here

3
  • I assume you put "would appear" in italics because you wondered why I didn't just try that myself. The reason is simply that I was not sure where to put the tikz environment. Thank you for posting a solution, it is exactly what I was looking for.
    – C.Carl
    Feb 4, 2020 at 12:14
  • Glad that it suits your needs. Don't take the would appear too seriously—it's just that we often see “Is it possible to... ?” questions and, when it is quite clear for me that the answer is “yes (but this requires some work),” it is tempting to only answer “yes”... but I refrain from doing so. :-)
    – frougon
    Feb 4, 2020 at 12:25
  • I see :) I'll make sure to just ask "How do I...?" in the future.
    – C.Carl
    Feb 4, 2020 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .