1

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

instead of

1 Title

Minimal example:

\documentclass{scrartcl}

\begin{document}

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

\end{document}

produces

enter image description here

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?

1 Answer 1

2

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}

enter image description here


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.

If there would be a table of contents add

\renewcommand*{\addsectiontocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\addtocentrydefault{section}{#1}{#2}}
    {\addtocentrydefault{section}{}{#2\enskip#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
\pagestyle{headings}

\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
\renewcommand*{\addsectiontocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\addtocentrydefault{section}{#1}{#2}}
    {\addtocentrydefault{section}{}{#2\enskip#1}}%
}


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

\end{document}

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .