# How to control the vertical skip of a boxed text?

I need to control the vertical skip between ordinary text and macro generated boxed objects in some documents I am redacting. Due to stylistic, reasons I need to respect the following rules:

1. If a boxed object is placed between two ordinary text blocks, a fixed vertical skip (say 0.2\baselineskip, for example) should be added above and below it.
2. The skip between two consecutive boxed objects should be the same as the one between a boxed object and a ordinary text block, i.e. it should not be doubled/multiplied.
3. If the box is placed at the start of a new paragraph, no additional vertical skip before it should be added. The same rule should be respected if the boxed object appears at the start of the new page.
4. No indentation should be added to the text block coming after a boxed object.

I tried the following, very simple, \simplepic command:

\documentclass[a4paper, 12pt, oneside]{book}

% Preamble

% structure settings

\usepackage{calc}

% lipsum
\usepackage{lipsum}

%%%% Single Image macro

\newcommand{\simplepic}[1]
{\vspace{.2\baselineskip}
\par\noindent
\fbox{%
\begin{minipage}[t]{\linewidth-2ex}
#1
\end{minipage}
}
\vspace{-.2\baselineskip}
\par\noindent
}

\begin{document}
\simplepic{\lipsum[1]}
\lipsum[2]
\simplepic{\lipsum[3]}
\lipsum[4]
\lipsum[5]
\simplepic{\lipsum[6]}
\simplepic{\lipsum[7]}
\lipsum[8]
\end{document}


The code works approximatively well in the sense that it produces vertical spacing according to rules 1, 3 and 4: however, rule 2 is not respected as a simple run of the above code shows in the second page of the resulting output .pdf file. In sum, my question is: how can I control the vertical spacing above or below a boxed object in order to make it independent on the presence of other boxed objects of the same class?

You need to use \addvspace (but after a paragraph has ended).

\documentclass[a4paper, 12pt, oneside]{book}

% Preamble

% structure settings

\usepackage{calc}

% lipsum
\usepackage{lipsum}

%%%% Single Image macro

\newcommand{\simplepicsep}{0.2\baselineskip}

\newcommand{\simplepic}[1]{%
\par
\noindent
\fbox{%
\begin{minipage}[t]{\linewidth-2ex}
#1
\end{minipage}% <--- don't forget this one
}
\par
}

\begin{document}
\simplepic{\lipsum[1]}
\lipsum[2]
\simplepic{\lipsum[3]}
\lipsum[4]
\lipsum[5]
\simplepic{\lipsum[6]}
\simplepic{\lipsum[7]}
\lipsum[8]
\end{document}


I'd avoid a trailing \noindent, that would start a paragraph. Using an environment, instead of a command, may help, because of built-ins for distinguishing whether the environment is followed by a blank line or not.

• Thank you very much. I briefly noticed the command in the Kopka-Daly, but I never used it. After you posted your answer, I remembered it and had a look also in the LaTEX Companion, where the command is characterized extensively. – Daniele Tampieri Feb 5 '18 at 14:08