2

When using KOMA-Script, one has \RedeclareSectionCommand available to adjust the spacing before/after section titles, as described in this question.

I want the content of the section to appear on the immediate next line under the section title, without any extra vertical space. The following mwe shows the content as I want it:

\documentclass{scrartcl} 
\begin{document}

\RedeclareSectionCommand[afterskip=1pt]{section} %the magic happens here

\section{Foo}
    This is some text to show off
\section{Bar}
    This is some text to show off
\section{Baz}
    This is some text to show off  
\end{document}

In my actual document however, I use parskip=full- as argument to \documentclass. This has the effect, that there will be an empty line between the section title and the section content, which I don't want. The mwe also shows this behaviour. Every allowed value for parskip with starts with full or half shows this behaviour.

I think this is the normal and expected behaviour, as the german documentation explicitly states that the whitespace preceedes the paragraph.

Because time is an issue right now, I hacked it by putting \vspace*{-\baselineskip} after every \section{}, but this is of course unacceptable for long term use.

How do I get the behaviour of parskip=full- and \RedeclareSectionCommand[afterskip=1pt]{section}, with the exception that I don't want any vertical space between the section title and the corresponsing content?

4

Update

It is still not recommanded but now possible without patching a command because KOMA-Script version 3.26 introduces two new keys to \RedeclareSectionCommand and \RedeclareSectionCommands: runin and afterindent. Possible values for both keys are bysign, true and false. For more information see the KOMA-Script documentation or eg Adjusting spacing around section/subsection titles with koma-script.

Using the new key runin with value false¹ it is possible to remove the \parskip between the heading and the following text by afterskip=-\parskip.

Example:

\documentclass[parskip=full-]{scrartcl}[2015/10/03]
\RedeclareSectionCommand[
  runin=false,
  afterskip=-\parskip
]{section}

\begin{document}
\section{Foo}
    This is some text to show off

    This is some text to show off
\section{Bar}
    This is some text to show off

    This is some text to show off
\section{Baz}
    This is some text to show off

    This is some text to show off
\end{document}

The (ugly) result is the same as in the original answer below.

¹ Default setting is runin=bysign which results in the same behavior as in the original answer.


Original answer

It is not recommended - see tex.stackexchange.com/a/300541/43317 and komascript.de/node/2039 (German) - but possible with KOMA-Script version 3.19 or newer:

\documentclass[parskip=full-]{scrartcl}[2015/10/03]
\RedeclareSectionCommand[afterskip=1sp]{section} %the magic happens here
\usepackage{xpatch}
\xapptocmd\sectionlinesformat{\vspace*{-\parskip}}{}{\PatchFailed}

\begin{document}
\section{Foo}
    This is some text to show off

    This is some text to show off
\section{Bar}
    This is some text to show off

    This is some text to show off
\section{Baz}
    This is some text to show off

    This is some text to show off
\end{document}

As you can see the result looks weird:

enter image description here

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.