8

Using the scrartcl document class, I would like to put the section number into the page margin, as is seen for example in the famous l2tabu document. That should be easily possible with KOMA-Script, but I can not find how.

Also, how can the same be done with page numbers, as is done for example in the good old LaTeX Companion?

6

Update

With KOMA-Script version 3.19a or newer you simple have to redefine \sectionlinesformat to get the desired result:

\documentclass{scrartcl}[2015/10/03]

\renewcommand\sectionlinesformat[4]{%
  \makebox[0pt][r]{#3}#4%
}

\usepackage[headwidth=textwithmarginpar]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\pagemark}
\usepackage{blindtext}
\begin{document}
\Blinddocument
\end{document}

Original answer

Since KOMA-Script version 3.17 (current version on CTAN) you have to redefine the commands \sectionformat, \subsectionformat etc. instead \othersectionlevelsformat.

\documentclass{scrartcl}[2015/04/23]
\renewcommand\sectionformat{\makebox[0pt][r]{\thesection\autodot\enskip}}
\renewcommand\subsectionformat{\makebox[0pt][r]{\thesubsection\autodot\enskip}}
\renewcommand\subsubsectionformat{\makebox[0pt][r]{\thesubsubsection\autodot\enskip}}

\usepackage[headwidth=textwithmarginpar]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\pagemark}

\usepackage{blindtext}
\begin{document}
\Blinddocument
\end{document}
7

The source code of l2tabu is available on CTAN. There you can read it:

\renewcommand*{\othersectionlevelsformat}[1]{%
  \makebox[0pt][r]{\csname the#1\endcsname\autodot\enskip}}

The section number is put into a box of width 0, right aligned. So it runs into the left margin.

2
  • I found the command for setting the pagenumber in the margin. \setheadwidth[0pt]{textwithmarginpar} Want to add it to your answer?
    – Ingo
    Jan 11 '12 at 11:53
  • 3
    The definition is flawed: \othersectionlevelsformat has three arguments. The KOMA-Script documentation (p. 109 of a current version) suggests \renewcommand*\othersectionlevelsformat[3]{\makebox[0pt][r]{#3\autodot\enskip}}
    – cgnieder
    Aug 20 '14 at 7:53

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.