1

I'm trying to outline section titles differently in a double sided document. In particular, I'd like to do so using KOMA script. When on an odd (right) page, the section title should be outlined right and the number should be displayed in the margin to the right; when on the left, the text should be outlined left, with the number to the left of it.

I've tried adapting this question to my needs, but haven't been successful. Case in point: when not editing that answer and simply adding the option twoside, I get:

img1 (a). This section's number isn't truly in the margin.

img2 (b). This section is outlined wrong, and its number isn't in the corresponding margin.

I'm trying to adapt this and still use KOMA script. My attempt was the following:

\documentclass[twoside]{scrartcl}[2015/10/03]
\usepackage{showframe}

% my edit:
\renewcommand\sectionlinesformat[4]{%
\ifthispageodd{%
    \raggedleft\makebox[0pt][r]{#4}#3}{%
    \raggedright\makebox[0pt][r]{#3}{#4}}
}

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

However, problem (a) is still very much there (unchanged), while problem (b) has now become:

img3

1
\documentclass[twoside]{scrartcl}
\usepackage{showframe}

\renewcommand\sectionlinesformat[4]{%
  \ifthispageodd
    {\raggedleft#4\makebox[0pt][l]{\enskip#3}}% <- changed
    {\raggedright\makebox[0pt][r]{#3}#4}% <- comment space at line end
}

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

enter image description here

If the section numbers should be in marginpar (area for the margin notes):

\documentclass[twoside]{scrartcl}
\usepackage{showframe}

\renewcommand\sectionformat{\thesection\autodot}
\renewcommand\subsectionformat{\thesubsection\autodot}
\renewcommand\subsubsectionformat{\thesubsubsection\autodot}

\renewcommand\sectionlinesformat[4]{%
\ifthispageodd
  {\raggedleft#4\makebox[0pt][l]{\hspace{\marginparsep}#3}}
  {\raggedright\makebox[0pt][r]{#3\hspace{\marginparsep}}#4}%
}

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

enter image description here

  • Thank you! Though still the number isn’t fully in the margin. – SvanN Jan 18 at 19:36
  • Do you mean the marginpar? Then see my updated answer. – esdd Jan 18 at 21:18
  • That is precisely what I was looking for! Thank you. – SvanN Jan 19 at 8:51

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.