How to remove space in section title at KOMA-Script

Here is MWE:

\documentclass{scrartcl}

\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}{%
}
{{\hskip#2#3}{#4}}%
}\makeatother

\begin{document}

\section{ABC}

\end{document}


The output is this:

I want it will be: 1. ABC and not 1 . ABC (no space between the "1" and the ".").
It is possible? and if it's possible, how can I do it?

Thank you!

• sorry, I am not able to compile your MWE (Font OrnementsADF not found). Just a guess: try to terminate every line that might be fragile with a %: \ifstr{#1}{section}{% {\adforn{30} {#3}. {#4} \adforn{58}}% }% – AndiW Mar 18 at 19:44

The macro \sectionformat contains an \enskip at the end. You can redefine it without that:

\documentclass{scrartcl}

\def\sectionformat{\thesection\autodot}% \enskip
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}{%
}
{{\hskip#2#3}{#4}}%
}\makeatother

\begin{document}

\section{ABC}

\end{document}


• Thank you!! What is the \csname command? – heblyx Mar 18 at 19:44
• @heblyx It allows you to use a control sequence (a.k.a. macro) by its name. One expansion of \csname thesection\endcsname gives \thesection. If you simply use \thesection it will work as well. The \csname thingy is just for dynamically creating these formatting commands. – Phelype Oleinik Mar 18 at 19:46
• @PhelypeOleinik - Using the \csname ... \endcsname machinery would seem to be overkill here. Maybe replace \csname thesection\endcsname \autodot with \thesection.\autodot? :-) – Mico Mar 18 at 20:04
• @Mico Indeed, unnecessary complication. Done :) – Phelype Oleinik Mar 18 at 20:09
• Note: This could result in two ., if \autodot results in adding a .. And IMHO the KOMA-Script guide recommends to add number format parts like the end dot to \sectionformat instead of \sectionlinesformat. See my answer about how to do this. – Schweinebacke Mar 18 at 20:32

You should reduce group braces to a minimum and add the . either to the \sectionformat:

\documentclass{scrartcl}

\renewcommand*{\sectionformat}{\thesection.\enskip}% replaced \autodot by .
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}%
{\hskip#2#3#4}%
}\makeatother

\begin{document}

\section{ABC}

\end{document}


or select numbers=withdot to add the dot to all section levels:

\documentclass[numbers=enddot]{scrartcl}

\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}%
{\hskip#2#3#4}%
}

\begin{document}

\section{ABC}

\end{document}


Both examples result in:

Note: You should not combine a \autodot in \sectionformat with a hard coded . (neither in \autodot nor on \sectionlinesformat where it is misplaced by specification), because this could result in two dots.

Please have a look to the KOMA-Script manual for the default of \sectionformat and the meaning of numbers=withdot, \sectionformat and \autodot.

BTW: The \makeatother in your example is also not necessary and should be removed (so I did).

Off-Topic: You should also avoid possible spurious white spaces by newlines after } or { and by real spaces in the middle of the code.

As a comment claims that this does not work with hebrew:

\documentclass[numbers=enddot]{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Simple CLM}

\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}%
{\hskip#2#3#4}%
}

\begin{document}

\section{גדה}

\end{document}


and

\documentclass{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Simple CLM}

\renewcommand*{\sectionformat}{\thesection.\enskip}% replaced \autodot by .
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}%
{\hskip#2#3#4}%
}

\begin{document}

\section{גדה}

\end{document}


both result in:

which seem to be correct for using RL.

• Your solution is good, but I'm not sure it's good for me. Because I'm Hebrew user - the dot is always at wrong side... at Hebrew it shuold be ".1" and not "1." – heblyx Mar 18 at 20:42
• It is possible? – heblyx Mar 18 at 21:23
• @heblyx Cannot reproduce this. See my hebrew example. – Schweinebacke Mar 19 at 11:42
• I will replace it. Thank you!! – heblyx Mar 19 at 14:58