# merge consecutive skips like css

I have a series of figure-like paragraphs generated by a command of mine, and would like to have a minimum amount of vertical space above and below these figure-like paragraphs, but I don't want the double the space when two of them follow eachother.

Using css, I would use the following code, since CSS merges two consecutive margins and leaves only a space equivalent to the largest :

.myclass { margin-top: 1cm; margin-bottom: 1cm; }


I can achieve the result I want (the same space above the first \mycommand, between the two \mycommand, and after the second \mycommand) using the following LaTeX code, but I would like to avoid the \vskip 1cm that I manually added after the second \mycommand :

\documentclass{article}
\usepackage{lipsum}
\def\mycommand{
\bgroup
\vskip 1cm
\rule{10cm}{2cm}
\par
\egroup
}
\begin{document}
\lipsum[1]
\mycommand
\mycommand
\vskip 1cm
\lipsum[2]
\lipsum[3]
\end{document}


If I choose the option to redefine \mycommand like this, then I have twice the space between the first \mycommand and the second :

\def\mycommand{
\bgroup
\vskip 1cm
\rule{10cm}{2cm}
\par
\vskip 1cm
\egroup
}


I have tried fiddling with TeX's glues (1cm minus 1cm for example), but didn't get the result I want.

-

LaTeX provides \addvspace{<len>} that adds vertical space only if needed, up to <len>. This seems to be what you're after:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\def\mycommand{
\bgroup
\rule{10cm}{2cm}
\par
\egroup
}
\begin{document}
\lipsum[1]
\mycommand
\mycommand
\lipsum[2]
\lipsum[3]
\end{document}


One area where \addvspace is commonly used is in ToC-entries (like the "List of Figures"/LoF) to denote the gap between chapter entries (in book and report document classes). For example, if some chapter has no figures, you don't want an additional (or larger) gap between the LoF entries. Here is an extract from the \chapter command in book.cls:

\addtocontents{lof}{\protect\addvspace{10\p@}}%

that adds 10pt.