Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Inserting \vspace* necessarily inserts space (regardless of where it's issued) while \vspace is a little less invasive (see Adding vertical space at the start of a page). Once you insert \vspace*{0em}, you already have "something" at the top of the page, followed by the regular \section top skip... –  Werner Jul 13 '12 at 22:46
1  
If you replace your \vspace*{0em} by \hbox{} (an empty box) you can see the same effect. This happens because \section inserts a vertical space at its top (which is discarded by tex if it is the first vertical material in a page, which is not the case after inserting \hbox or \vspace*). So the question should be "How can I remove the vertical space that the next command will insert?". I don't know the answer for this one. –  JLDiaz Jul 13 '12 at 22:52
    
@Werner I know that already, but how does this help? –  Ronny Jul 14 '12 at 0:03
    
@JLDiaz Yes, noticed this by replacing \vspace*{0em} with \null. Seems to have something to do with the definition of \section: \newcommand{\subsection}{\@startsection{subsection}{1}{\z@}{-0.2ex}{2.3ex \@plus.2ex} .... Like you wrote: How to force LaTeX not to add extra space as there is no object before \section? –  Ronny Jul 14 '12 at 0:10
    
Please accept that there is an object before \section if you insert one with \null or \vspace*. This might be an argument from a technical POV, but you won't be able to change anything about that. –  Stephan Lehmke Jul 14 '12 at 6:48

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Does any one know where the little extra space comes from? –  Ronny Jul 14 '12 at 11:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.