0

I am using blocks on the side of the page to show the chapter number. I am using the example described on this forum (here). However, I would like to turn the chapter numbers by 90 degrees. I tried the angle option at several places, but nothing worked. Here is my MWE:

\documentclass[twoside,openright,numbers=endperiod,titlepage,headinclude,
                footinclude=false,cleardoublepage=empty,abstractoff,
                BCOR=5mm,b5paper,fontsize=11pt, american,
                ]{scrreprt}

\usepackage{tikzpagenodes}
\usepackage{totcount}


%makes blocks with chapter number on the side of the page
\newif\ifMaterial
\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\AtBeginDocument{%
\regtotcounter{chapter}
\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\ifdim\LabelSize>2.5cm\relax
  \global\setlength\LabelSize{2.5cm}
\fi
}
\newcommand\AddLabels{%
\Materialtrue%
\AddEverypageHook{%
\ifMaterial%
\ifodd\value{page} %
 \backgroundsetup{
  angle=90,
  position={current page.east|-current page text area.north  east},
  vshift= 10pt,
  hshift=-\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!50,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \else
 \backgroundsetup{
  angle=90,
  position={current page.west|-current page text area.north west},
  vshift=-10pt,
  hshift=-\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!50,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \fi
 \BgMaterial%
\else\relax\fi}%
}
\newcommand\RemoveLabels{\Materialfalse}

\begin{document}

\include{Chapters/Introduction}
\cleardoublepage

\end{document}
1

I was not able to compile your Minimal Working Example. But I took it from here.

You were right, to rotate the chapter number, you have to play with the angle option. But you also have to change its position (with the two options vshift and hshift).

\documentclass[openany,english]{scrbook}
\usepackage[contents={},opacity=1,scale=1,color=black]{background}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{totcount}
\usepackage{lipsum}% just to generate text for the example
\usepackage{babel}
\usetikzlibrary{calc}

\newif\ifMaterial

\newlength\LabelSize
\setlength\LabelSize{2.5cm}

\AtBeginDocument{%
\regtotcounter{chapter}
\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\ifdim\LabelSize>2.5cm\relax
  \global\setlength\LabelSize{2.5cm}
\fi
}

\newcommand\AddLabels{%
\Materialtrue%
\AddEverypageHook{%
\ifMaterial%
\ifodd\value{page} %
 \backgroundsetup{
  angle=-90,
  position={current page.east|-current page text area.north east},
  vshift=-15pt,
  hshift=\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \else
 \backgroundsetup{
  angle=-90,
  position={current page.west|-current page text area.north west},
  vshift=15pt,
  hshift=\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \fi
 \BgMaterial%
\else\relax\fi}%
}

\newcommand\RemoveLabels{\Materialfalse}

\begin{document}

\chapter{Test Chapter One}
\AddLabels
\lipsum[1-2]
\chapter{Test Chapter Two}
\lipsum[1-2]
\chapter{Test Chapter Three}
\lipsum[1-2]
\chapter{Test Chapter Four}
\lipsum[1-2]
\chapter{Test Chapter Five}
\RemoveLabels
\lipsum[1-2]

\end{document}
| improve this answer | |
2

I do not really understand how the chapter numbers should be rotated. But here is a suggestion using package scrlayer-scrpage to define a new pair of layer page styles.

\documentclass[
    twoside,open=right,
    numbers=endperiod,
    titlepage,
    headinclude,
    abstract=off,
    BCOR=5mm,
    a6paper,
    american,
]{scrreprt}
\usepackage{babel}

\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\newcommand\LabelWidth{25pt}
\newcommand\Angle{90}% change the angle here

\usepackage{totcount}
\AtBeginDocument{%
    \regtotcounter{chapter}
    \setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
    \ifdim\LabelSize>2.5cm\relax
        \global\setlength\LabelSize{2.5cm}
    \fi
}

\usepackage{xcolor}
\usepackage{rotating}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\ofoot*{\pagemark}

\DeclareNewLayer[
    background,
    oddpage,
    textarea,
    width=\LabelWidth,
    height=\LabelSize,
    hoffset=\dimexpr\paperwidth-\LabelWidth\relax,
    addvoffset=\dimexpr-\LabelSize+\LabelSize*\value{chapter}\relax,
    mode=picture,
    contents={%
        \putLL{\textcolor{lightgray}{\rule{\layerwidth}{\layerheight}}}%
        \putC{\makebox[0pt]{\rotatebox[origin=c]{\Angle}{\raisebox{-.5\height}{%
            \Large\bfseries\sffamily\thechapter
        }}}}%
    }
]{chapnumbox.odd}
\DeclareNewLayer[
    clone=chapnumbox.odd,
    evenpage,
    hoffset=0pt
]{chapnumbox.even}

\DeclareNewPageStyleByLayers
    [onselect={\DeclarePageStyleAlias{plain}{plain.chapnumbox}}]
    {chapnumbox}{chapnumbox.odd,chapnumbox.even}
\DeclareNewPageStyleByLayers
    {plain.chapnumbox}{chapnumbox.odd,chapnumbox.even}

\AddToLayerPageStyleOptions{scrheadings}
    {onselect={\DeclarePageStyleAlias{plain}{plain.scrheadings}}}

\ForEachLayerOfPageStyle{scrheadings}
    {\AddLayersToPageStyle{chapnumbox}{#1}}
\ForEachLayerOfPageStyle{plain.scrheadings}
    {\AddLayersToPageStyle{plain.chapnumbox}{#1}}

\usepackage{lipsum}% just to generate text for the example
\begin{document}

\tableofcontents
\clearpage
\pagestyle{chapnumbox}
\chapter{Chapter One}
\lipsum
\chapter{Chapter Two}
\lipsum
\chapter{Chapter Three}
\lipsum
\chapter{Chapter Four}
\lipsum
\chapter{Chapter Five}
\lipsum
\clearpage
\pagestyle{scrheadings}
\addchap{Test Chapter without Number}
\lipsum[1-2]
\end{document}

Result:

enter image description here

and with

\newcommand\Angle{-90}

enter image description here

or with

\newcommand\Angle{0}

enter image description here

| improve this answer | |
  • This works, besides the numbers are not placed in the grey boxes. But then I have to use a different pagestyle (as you defined the chamnumbox), but I have more lay-out things in my pagestyle, which will get lost using this one (like chapter title on top of the page). – Brigitte Bruijns Feb 8 '17 at 15:37
  • The new defined pagestyle chapnumbox uses all the layers of pagestyle scrheadings. So you can still use \ohead etc. to put contents in the header or footer. Or do you load a different package for header and footer? If you add your settings to your MWE, I can show how this can be done by package scrlayer-scrpage. – esdd Feb 8 '17 at 16:05
  • I have all the lay-out setting in one 'master'file in which the chapters are loaded, so no separate package or file. I am now using the fancy pagestyle, with fancyhead and fancyfoot. – Brigitte Bruijns Feb 10 '17 at 11:21
  • If your are using \fancyhead and \fancyfoot and pagestyle fancy then package fancyhdr is used by your code probably. Maybe you can replace this package by scrlayer-scrpage and its commands. But if you want to keep fancyhdr then you can not use my suggestion. – esdd Feb 10 '17 at 12:45
1

To make your MWE working, you need to add \usepackage[contents={},opacity=1,scale=1,color=black]{background} to your preamble.

In your document, you have to add \AddLabels to activate the code.

This is the complete MWE

\documentclass[twoside,openright,numbers=endperiod,titlepage,headinclude,
                footinclude=false,cleardoublepage=empty,abstractoff,
                BCOR=5mm,b5paper,fontsize=11pt, american,
                ]{scrreprt}
\usepackage{lipsum}
\usepackage[contents={},opacity=1,scale=1,color=black]{background}

\usepackage{tikzpagenodes}
\usepackage{totcount}


%makes blocks with chapter number on the side of the page
\newif\ifMaterial
\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\AtBeginDocument{%
\regtotcounter{chapter}
\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\ifdim\LabelSize>2.5cm\relax
  \global\setlength\LabelSize{2.5cm}
\fi
}
\newcommand\AddLabels{%
\Materialtrue%
\AddEverypageHook{%
\ifMaterial%
\ifodd\value{page} %
 \backgroundsetup{
   angle=90,
  position={current page.east|-current page text area.north  east},
  vshift=10pt,
  hshift=-\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!50,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \else
 \backgroundsetup{
  angle=90,
  position={current page.west|-current page text area.north west},
  vshift=-10pt,
  hshift=-\thechapter*\LabelSize,
  contents={%
  \tikz\node[fill=gray!50,anchor=west,text width=\LabelSize,
    align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};
  }%
 }
 \fi
 \BgMaterial%
\else\relax\fi}%
}
\newcommand\RemoveLabels{\Materialfalse}

\begin{document}

\AddLabels
\chapter{First Chapter}
\lipsum[1-2]
\lipsum[1-3]
\cleardoublepage
\chapte{Second Chapter}
\lipsum[1-3]

\end{document}
| improve this answer | |
  • @JohnKormylo: Thanks. I removed the \includes by more verbatim code. – Jan Dec 19 '16 at 16:10
  • Yes, I forgot to add them. Thanks for doing that! – Brigitte Bruijns Feb 8 '17 at 11:55

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.