[Tex/LaTex] How to remove extra space between \vspace*{0em} and \section

sectioningspacing

I want to add an exact amount of space between type area and a section:

\documentclass{scrbook}

\KOMAoptions{fontsize=10pt, paper=14cm:21cm, DIV=calc, pagesize=auto, BCOR=5mm,     twoside=true, titlepage=true}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}

% shows frames of type area (good for debugging)
\usepackage{showframe}

\begin{document}

%\vspace*{-\topskip}  % removes \topskip space
\vspace*{0em}  % space amout is 0em for testing purpose; remove or comment to get absolutely no space
\section{Test}

\end{document}

I think the command \vspace*{0em} expands the section’s glue, right? If I remove \vspace*{0em} the section is on the top of the type area. Somehow \vspace*{0em} should do the same thing. The background is that I want to add an exact space between type area and section, but it’s always to much space. Any idea to fix this?

Best Answer

My own not perfectly working solution is:

\documentclass{scrbook}

\KOMAoptions{fontsize=10pt, paper=14cm:21cm, DIV=calc, pagesize=auto, BCOR=5mm, twoside=true, titlepage=true}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
% shows frames of type area (good for debugging)
\usepackage{showframe}

\makeatletter
% change definition of \section; remove space before
\renewcommand{\section}{\@startsection{section}{1}{\z@}%
  {-0.01ex}%
  {2.3ex \@plus.2ex}%
  {\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@section}%
}
\makeatother


\begin{document}

\vspace*{-\topskip}
\section{Test}

Test

\end{document}

The code redefines the \section command in the way that the space before is set to -0.01ex (must be a negative number to avoid paragraph indention). There is only a little bit space left. Remove or comment out \vspace*{-\topskip} to see test this.