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.

Knowing about \addvspace I wrote my own environment that adds a minimum space before and after it. But using memoir, if a \section precedes it, \addvspace always adds all its space to the space that usually follows a section. MWE:

\documentclass{memoir}

\usepackage{lipsum}

\begin{document}

\section{Sec 1}

\lipsum[1]

\section{Sec 2}

\addvspace{\onelineskip}
\lipsum[1]

\section{Sec 3}

\section{Sec 4}

\end{document}

You can see that the second section has way too much vspace after it. I had a look at the memoir \@startsection code and found that it does (rightly) use \vskip and \addvspace. After reading this question I suspect it is maybe a \noindent problem since \@afterindent is used. But there must be a trick somewhere that I am missing because Sec 3 and Sec 4 have the proper space. Any ideas of how to fix this?

share|improve this question
2  
The problem is that the last skip called by \section is \vskip-\parskip which is 0pt plus -1pt and so when \addvspace tests whether the last skip is zero (in which case it always adds its space), the test will be true because the first component of the skip is 0pt (the plus part is discarded). To solve your problem, you can put an \unskip just before your \addvspace. –  Philippe Goutet Oct 7 '12 at 7:07
    
@PhilippeGoutet This deserve to be an answer =:-) –  Sveinung Oct 7 '12 at 8:00
    
Hm.. it sounds promising, but it doesn't quite work yet: it breaks with "You can't use \unskip in vertical mode." Is there an equivalent for vertical mode? And a conditional one that only unskips if the \vskip was 0pt? –  MiB Oct 7 '12 at 14:59
    
@MiB: Sorry, I should have mentioned it, but for \unskip to work, you mustn't leave a blank line before it (so it's more a one time quick fix than a real solution). –  Philippe Goutet Oct 7 '12 at 18:24
add comment

1 Answer

up vote 3 down vote accepted

Aha! Thanks to the tip from Philippe I found the following solution:

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@xsect}
         {\vskip\@tempskipa\vskip-\parskip}{\addvspace{\@tempskipa}\addvspace{-\parskip}}
         {}{\typeout{WARNING! Patching \noexpand\@xsect failed!}}
\makeatother

\@xsect didn't use \addvspace but plain \vskip. Changing that fixes my problem.

share|improve this answer
add comment

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.