I have document with custom environment myenv
which left margin is 4em.
\documentclass{book}
\usepackage{lipsum}
\newenvironment{myenv}{
\setlength{\leftskip}{4em}
}
\begin{document}
\lipsum[1-2]
\begin{myenv}
Vertical space should be here.
\lipsum[3-5]
Vertical space should be here.
\end{myenv}
\lipsum[6]
\end{document}
I want to add vertical space around this environment - that is before/above and after/below. Most straightforward, but at the same time labor-intensive, way to accomplish this that I know of is:
\begin{document}
\lipsum[1-2]
\begin{myenv}
\vspace{2em}
\lipsum[3-5]
\vspace{2em}
\end{myenv}
\lipsum[6]
\end{document}
Since I want to be able to change this vertical space without changing vertical spaces in rest of the document, I use macro:
\documentclass{book}
\usepackage{lipsum}
\newenvironment{myenv}{
\setlength{\leftskip}{4em}
}
\def \myvspacemacro{
\vspace{2em}
}
\begin{document}
\lipsum[1-2]
\begin{myenv}
\myvspacemacro{}
\lipsum[3-5]
\myvspacemacro{}
\end{myenv}
\lipsum[6]
\end{document}
Is there any easier and faster way of doing this? Ideally, I would like to set length of top vertical space and bottom vertical space for environment same way as I set leftskip value. Is it possible? There are 2 similar questions: Proper way of vertical spacing before/after environments, Vertical space before and after custom environment, but none of them seems to solve situation like mine.
Simply put, I want to achieve same effect as I would achieve in HTML/CSS by using margin-top and margin-bottom properties.
I also tried to add \vspace
to my environment definition, but it only adds margin on top of environment and leaves no margin below environment.
\documentclass{book}
\usepackage{lipsum}
\newenvironment{myenv}{
\vspace{2em}
\setlength{\leftskip}{4em}
}
\begin{document}
\lipsum[1-2]
\begin{myenv}
\lipsum[3-5]
\end{myenv}
\lipsum[6]
\end{document}
\leftskip
directly in latex, it will cause any nested list or display environment to be misplaced. Always use a list for this. Also you normally ant to use \addvspace rather than \vspace so the space combines with other display environments. (and you have loads of missing%
at ends of lines:-)