5

I like the way the section numbering is typeset in the book Convex Optimization, i.e. the sections numbers are placed in the margin.enter image description here

How do I achieve this style with the scrbook class from the KOMA-script package?

Partial Solution: This code snippet seems to do the trick, but, as cgnieder points out in the comment section below, the numbers are not centered relative to each other.

  • Could you explain yourself better and add an Minimal Working Example (MWE) for see what you need. We don't know if you're working with the scrartcl class o another. – Aradnix Aug 19 '14 at 06:19
  • On the first glance, there is nothing special about this, except from (apparently?) centered section number over the subsection number. By the way: amsbook class and KOMA are very different classes/packages. –  Aug 19 '14 at 06:35
  • @ChristianHupfer: Notice that the section numbers are placed in the margin. – Christopher Aug 19 '14 at 06:40
  • @ChristopherMorris: It could be the margin, it could be that the content is indented ... it's hard to say from this screen shot –  Aug 19 '14 at 06:42
  • @ChristianHupfer but the latter would seem rather strange to me. Besides: if it is the latter then effectively the margin is bigger and the numbers still are in the margin :) – cgnieder Aug 19 '14 at 06:46
  • @cgnieder: That depends on the opinion, what belongs to the margin ;-) –  Aug 19 '14 at 06:48
  • @ChristianHupfer: Good point, have a look at http://stanford.edu/~boyd/cvxbook/bv_cvxbook.pdf.

    At least on pages with an odd page number the section numbers seem to be placed in the margin.

    – Christopher Aug 19 '14 at 06:53
  • I added a solution. – Christopher Aug 19 '14 at 07:03
  • @ChristopherMorris with the solution of the link you added the numbers will be placed in the margin. In the picture in your post they're also centered relative to each other which the linked solution doesn't have. – cgnieder Aug 19 '14 at 07:06
  • @cgnieder: Good point, I would prefer the later. – Christopher Aug 19 '14 at 07:10

1 Answers1

5

You can use a modified version of the linked solution. In the linked solution you have

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

This puts the sectioning number in a box of zero width aligned to the right which is why the number sticks into the margin. The \enskip ensures a distance of 1en between number and heading. It is flawed, though. As the KOMA-Script manual describes \othersectionlevelsformat has three arguments and the 3rd is the corresponding \the<counter. A better definition would be

\renewcommand*\othersectionlevelsformat[3]{%
  \makebox[0pt][r]{#3\enskip}%
}

Now that the definition is corrected we can adjust it. In order to have the numbers horizontally centered to each other you could put a second box into the first with a certain given width (1.5cm, say) and have the contents centered:

\renewcommand*\othersectionlevelsformat[3]{%
  \makebox[0pt][r]{\makebox[1.5cm][c]{#3\autodot}}%
}

enter image description here

\documentclass{scrartcl}

\renewcommand*\othersectionlevelsformat[3]{%
  \makebox[0pt][r]{\makebox[1.5cm][c]{#3\autodot}}%
}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}

Adjusting this to scrbook and chapters is easy: we just need a corresponding definition for \chapterformat. This command has no arguments and we use \thechapter for placing the number.

\documentclass{scrbook}

\newcommand*\marginnumber[1]{\makebox[0pt][r]{\makebox[1.5cm][c]{#1}}}
\renewcommand*\chapterformat{\marginnumber{\thechapter\autodot}}
\renewcommand*\othersectionlevelsformat[3]{\marginnumber{#3\autodot}}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}
cgnieder
  • 66,645
  • Thanks, is it possible to extend your solution to chapter headings? – Christopher Aug 19 '14 at 20:40
  • 1
    Sure. I'll add something tomorrow. (It's late on my side of the world :)) – cgnieder Aug 19 '14 at 20:46
  • 1
    @ChristopherMorris I added something and discovered that the definition from the blog post is flawed. Maybe you should tell the author – cgnieder Aug 20 '14 at 06:56
  • One more question, is it possible to adapt the above code such that the chapter number is in the margin and the chapter title is centered? – Christopher Aug 22 '14 at 16:57
  • @ChristopherMorris probably. But I'd have to investigate how as well. Probably best if you ask a new question... – cgnieder Aug 22 '14 at 17:09
  • I asked a new question: http://tex.stackexchange.com/questions/197516/place-chapter-numbers-in-the-margin-and-center-chapter-titles. – Christopher Aug 22 '14 at 17:27