Page LayoutPlace chapter/section in left/right margin instead of top margin

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Daedalus
Posts: 2
Joined: Mon Dec 20, 2021 3:56 pm

Place chapter/section in left/right margin instead of top margin

Post by Daedalus »

Hello,

I agreed with a publisher to write my book in LaTeX and they sent me a number of different styles from which I picked one and which I am trying to replicate. The one that I have chosen does not indicate the chapter and section in the header but in the left and right margin as vertical text. To illustrate this, I attached a sample.

I am wondering if a package exists that does this and ion somebody can help me. Thanks!
Attachments
sample.pdf
(43.6 KiB) Downloaded 263 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Daedalus
Posts: 2
Joined: Mon Dec 20, 2021 3:56 pm

Place chapter/section in left/right margin instead of top margin

Post by Daedalus »

In the end, I came up with a solution which is easier than I thought and which I copy in the following for those interested.

First, I redefine how the chapters and sections are presented:

\renewcommand{\chaptermark}[1]%
{\markboth{{\thechapter.\ #1}}{}}
\renewcommand{\sectionmark}[1]%
{\markright{{\thesection.\ #1}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newcommand{\helv}{%
\fontfamily{put}\fontsize{10}{11}\selectfont}


Then I define the following two boxes (one for the chapter, another for the section) which can then be used with fancy headers by using \fancyhead[LE]{\marginchapter} and \fancyfoot[RO]{\marginsection}:

\newcommand{\marginchapter}{%
\makebox[0em][r]{% make the box extend into margin
\raisebox{0ex}[0ex][0ex]{% make the box have 0 hgt and dpth
\rotatebox[origin=rB]{90}{% rotate it
\colorbox{white}{\color{gray}\leftmark \ \ \color{black}\thepage}}}%
\hspace*{2em}% how far, horiz, box is from leftmargin
}}


\newcommand{\marginsection}{%
\makebox[0em][r]{% make the box extend into margin
\raisebox{0ex}[0ex][0ex]{% make the box have 0 hgt and dpth
\rotatebox[origin=rB]{-90}{% rotate it
\colorbox{white}{\color{gray}\rightmark \ \ \color{black}\thepage}}}%
\hspace*{-3em}% how far, horiz, box is from leftmargin
}}
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Place chapter/section in left/right margin instead of top margin

Post by Ijon Tichy »

Seems that the running head is without chapter number, but the bold number is the page number. Here is a suggestion for it:

Code: Select all

\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{scrlayer}
\usepackage{blindtext}

\automark[chapter]{chapter}

\DeclareLayer[background,evenpage,
  textarea,
  addhoffset=-\marginparsep-\baselineskip,
  width=\baselineskip,
  contents={\sffamily\rotatebox[origin=r]{90}{\leftmark\quad\pagemark}}
]{evenpagemark}

\DeclareLayer[background,oddpage,
  textarea,
  addhoffset=\textwidth+\marginparsep,
  width=\baselineskip,
  contents={\sffamily\rotatebox[origin=l]{270}{\makebox[\textheight][r]{\leftmark\quad\pagemark\enskip}}}
]{oddpagemark}

\DeclarePageStyleByLayers{sidemarks}{evenpagemark,oddpagemark}
\renewcommand*{\chapterpagestyle}{sidemarks}% Use the new page style also for chapter pages.

\renewcommand*{\chaptermarkformat}{}% Don't show chapter number in the marks
\setkomafont{pagenumber}{\bfseries}

\pagestyle{sidemarks}

\begin{document}
\tableofcontents
\blinddocument
\end{document}
See the KOMA-Script manual for more information about using scrlayer. Usually it is used via scrlayer-scrpage. But the example above shows, that it also can be used directly to define your own layer page style(s).

You can use the package also with a standard class. But the standard class book always uses page style plain for the chapter start page. So if you want to use the new pagestyle sidemarks also for the chapter start page (as shown above) you have to redefine pagestyle plain too:

Code: Select all

\documentclass{book}
\usepackage{graphicx}
\usepackage[markcase=noupper]{scrlayer}
\usepackage{blindtext}

\automark[chapter]{chapter}

\DeclareLayer[background,evenpage,
  textarea,
  addhoffset=-\marginparsep-\baselineskip,
  width=\baselineskip,
  contents={\sffamily\rotatebox[origin=r]{90}{\leftmark\quad\pagemark}}
]{evenpagemark}

\DeclareLayer[background,oddpage,
  textarea,
  addhoffset=\textwidth+\marginparsep,
  width=\baselineskip,
  contents={\sffamily\rotatebox[origin=l]{270}{\makebox[\textheight][r]{\leftmark\quad\pagemark\enskip}}}
]{oddpagemark}

\DeclarePageStyleByLayers{sidemarks}{evenpagemark,oddpagemark}
\DeclarePageStyleAlias{plain}{sidemarks}% Make pagestyle plain be the same like pagestyle sidemarks

\renewcommand*{\chaptermarkformat}{}% Don't show chapter number in the marks
\setkomafont{pagenumber}{\bfseries}

\pagestyle{sidemarks}

\begin{document}
\tableofcontents
\blinddocument
\end{document}
But now, every plain page is a sidemarks page. So maybe you need to define a new plain pagestyle named, e.g., realplain. Because of easy configuration of things like \chapterpagestyle I like the KOMA-Script classes more.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply