标签中的章节号旋转

标签中的章节号旋转

我在页面侧面使用块来显示章节编号。我使用此论坛上描述的示例(这里)。但是,我想将章节号旋转 90 度。我在几个地方尝试了角度选项,但都不起作用。这是我的 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

我无法编译你的最小工作示例。但我从这里

您说得对,要旋转章节号,您必须使用 选项angle。但您还必须更改其位置(使用vshift和两个选项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}

答案2

我不太明白章节号应该如何旋转。但这里有一个建议,使用包scrlayer-scrpage来定义一对新的图层页面样式。

\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}

结果:

在此处输入图片描述

\newcommand\Angle{-90}

在此处输入图片描述

\newcommand\Angle{0}

在此处输入图片描述

答案3

为了使您的 MWE 发挥作用,您需要添加\usepackage[contents={},opacity=1,scale=1,color=black]{background}到您的序言中。

在您的文档中,您必须添加\AddLabels激活代码。

这是完整的 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}

相关内容