# Too much space between framed box and section title

In my LaTeX document, I have some sections that contain normal text and other sections that contain text in a box, for which I use the \framed package.

When I try to increase the spacing below my section titles, I get the following problem: Now, the space between the frame box and the section title is larger than it is between normal text and the section title:

This doesn't happen with the default section spacing.

Does anybody know how I get the frames to have the same top margin as normal text?

\documentclass[10pt,a4paper]{scrartcl}

\usepackage{framed}
\usepackage{titlesec}

\setlength\parindent{0pt}

\titlespacing*{\section}{0pt}{8ex}{4ex}
\titlespacing*{\subsection}{0pt}{8ex}{4ex}

% ------------------

\begin{document}

\section{First section}
Here is text with the correct margin above the text.

\section{Second section}
\begin{framed}
Here is framed text with too much space above the frame.
\end{framed}

\end{document}

• Note that when you run your MWE you get lots of complaints in the .log file. KOMA complains that you shouldn't use titlesec with KOMA (you should use KOMA's own features). titlesec complains about non-standard sectioning commands. – moewe Dec 16 '16 at 14:52
• @moewe yeah, this seems to be the problem, I now got it to work with \RedeclareSectionCommand. Thank you! – Baleb Dec 16 '16 at 15:56
• If you solved your own question, please do not hesitate to post your solution as an answer (and accept it - after a waiting period). – moewe Dec 16 '16 at 15:58

As moewe pointed out, titlesec apparently shouldn't be used with KOMA. I got it to work correctly using the following command instead:

\RedeclareSectionCommand[afterskip=1.5em]{section}