1

How can I create a thin box box with the numbering of the current chapter on (for normal text page styles)? in the vertical middle of each even page e.g. a thin stripe at the right end of the page like this

enter image description here

2

2 Answers 2

1

You can place random content on a page during the page shipout routine via eso-pic.

The example below inserts the chapter number (represented by \thechapter) vertically centred on the right side of the page. An extra conditional \showchapterthumb<TF> turns on the showing of the chapter number thumbs if set to \..true. The default is \..false.

enter image description here

\documentclass{report}

\usepackage{lipsum}
\usepackage{eso-pic,xcolor}

\definecolor{chapterthumbbg}{HTML}{6F7175}

\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \ifshowchapterthumb\ifodd\value{page}\else
      \makebox[\paperwidth][r]{%
        \raisebox{\dimexpr.5\paperheight-.5\height}{%
          \setlength{\fboxsep}{\baselineskip}%
          \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
        }%
      }%
    \fi\fi
  }
}

\newif\ifshowchapterthumb

\sloppy% Just for this document

\begin{document}

\showchapterthumbfalse% Default

\tableofcontents

\clearpage

\showchapterthumbtrue% Show chapter thumbs

\chapter{First chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Second chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Third chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Last chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\end{document}

Background page numbers have been added for visual purposes only.

4
  • ... can we move the box slightly more to the right ... all the way to the left edge of the page? now there are a few millimeters in between :)
    – Stücke
    Commented Oct 29, 2017 at 19:37
  • @Jonas: I accidentally forgot to place a specific % within the definition. I've corrected that in the example code above.
    – Werner
    Commented Oct 30, 2017 at 1:01
  • How can I have this on both pages? Right and left
    – Stücke
    Commented May 7, 2018 at 18:28
  • @Jonas: Here's some code that does that. You can just update it to suit your needs.
    – Werner
    Commented May 7, 2018 at 18:48
2

Something like this? It's easy with  titleps, which comes with titlesec:

    \documentclass[12pt, twoside]{book}%

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[svgnames]{xcolor}
    \usepackage[showframe, nomarginpar]{geometry}
    \usepackage[pagestyles]{titlesec}
    \usepackage{lipsum}

    \newpagestyle{mine}{%
    \widenhead[2em][0em]{0em}{0em}
    \sethead[\smash{\colorbox{SlateGrey!70}{\rule[-1.5ex]{0pt}{5ex}\sffamily\Large\bfseries\thechapter}}][][]{}{}{}
    \setfoot{}{}{}
    }
    \pagestyle{mine}

    \begin{document}

    \chapter{introduction}
    \lipsum[1-8]

    \end{document} 

enter image description here

A variant: define page style as

   \newpagestyle{thine}{%
    \widenhead[2em][0em]{0em}{0em}
    \sethead[\raisebox{-\dimexpr\headsep+\headheight+2ex\relax} {\colorbox{SlateGrey!70}{\rule[-1.5ex]{0pt}{5ex}\sffamily\Large\bfseries\thechapter}}][][]{}{}{}
    \setfoot{}{}{}
    }

to obtain this: enter image description here

Edit: I think I've understood what you want. Does this code yield what you want?

    \newpagestyle{midpage}{%
    \widenhead[2em][0em]{0em}{0em}
    \sethead[\raisebox{-\dimexpr\headsep+\headheight+0.5\textheight\relax}{\colorbox{SlateGrey!70}{\parbox{1.4em}{\centering\rule[-2.8ex]{0pt}{8ex}\sffamily\Large\bfseries\thechapter}}}][][]{}{}{}
    \setfoot{}{}{}
    }
    \pagestyle{midpage}

enter image description here

3
  • Looking good, thanks! I'll try it myself later on :)
    – Stücke
    Commented Oct 27, 2017 at 14:49
  • Is there a way to move the number to the right side and vertical middle?
    – Stücke
    Commented Oct 27, 2017 at 14:52
  • To the right side certainly, but what do you mean with ‘vertical middle’?
    – Bernard
    Commented Oct 27, 2017 at 15:03

You must log in to answer this question.

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