2

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

SvanN
  • 562

1 Answers1

1
\documentclass[twoside]{scrartcl}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\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}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\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

esdd
  • 85,675