# Swap section title and section number in KOMA Script scrartcl

Since it is not recommended to use titlesec in KOMA script, I'm looking for some alternative to swap section title and section number, having

Title 1


1 Title


Minimal example:

\documentclass{scrartcl}

\begin{document}

\section{Title}
\section{Title}
\section{Title}

\end{document}


produces

All solutions I found use the titlesec package - which work with scrartcl indeed, but produces warnings:

Package titlesec Warning: Non standard sectioning command \section
(titlesec) detected. Using default spacing and no format.
Package titlesec Warning: Non standard sectioning command \subsection
(titlesec) detected. Using default spacing and no format.
Package titlesec Warning: Non standard sectioning command \subsubsection
(titlesec) detected. Using default spacing and no format.
Package titlesec Warning: Non standard sectioning command \paragraph
(titlesec) detected. Using default spacing and no format.
Package titlesec Warning: Non standard sectioning command \subparagraph
(titlesec) detected. Using default spacing and no format.
)
Class scrartcl Info: Unknown titesec' release.
(scrartcl) Cross your fingers, that is compatible on input line 9.


How can I swap number and title without warnings in scrartcl?

You have to redefine \sectionlinesformat and \sectionformat:

\documentclass{scrartcl}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\Ifstr{#1}{section}
{\@hangfrom{\hskip #2}{#4#3}}
{\@hangfrom{\hskip #2#3}{#4}}% original definition for subsection, subsubsection
}
\makeatother
\renewcommand\sectionformat{\enskip\thesection\autodot}

\begin{document}
\section{Title}
\section{Title}
\section{Title}
\end{document}


Regarding a comment below: If you want to use page style headings then you can add

\makeatletter
\renewcommand*{\sectionmark}[1]{%
\if@twoside\expandafter\markboth\else\expandafter\markright\fi
{\MakeMarkcase{#1\Ifnumbered{section}{\sectionmarkformat}{}}}{}}%
\makeatother
\renewcommand*\sectionmarkformat{\enskip\thesection\autodot}


to swap section number and section title in header.

\renewcommand*{\addsectiontocentry}[2]{%
\IfArgIsEmpty{#1}
}


Example:

\documentclass{scrartcl}
\usepackage{lipsum}% only for dummy text
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
%\providecommand*\Ifnumbered{\ifnumbered}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\renewcommand*\sectionformat{\enskip\thesection\autodot}
\renewcommand*\sectionmarkformat{\enskip\thesection\autodot}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\Ifstr{#1}{section}
{\@hangfrom{\hskip #2}{#4#3}}
{\@hangfrom{\hskip #2#3}{#4}}% original definition for subsection, subsubsection
}
\renewcommand*{\sectionmark}[1]{%
\if@twoside\expandafter\markboth\else\expandafter\markright\fi
{\MakeMarkcase{#1\Ifnumbered{section}{\sectionmarkformat}{}}}{}}%
\makeatother
\IfArgIsEmpty{#1}
}

\begin{document}
\tableofcontents
\section{Title}
\section{Title}
\section{Title}
\lipsum

\end{document}
`

• Thank you! But that doesn't change the order in e.g. the heading. How can I reorder it there as well? – ATW Apr 8 at 20:32