0

I found this answer to another question Spacing around table and figure environments.

I don't want to create a new environment for my figures. Instead I would like to edit the existing figure environment with the same \vspace{...} settings.

Is this possible?

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\newenvironment{MyFigure}[1][]{\begin{figure}[#1]\vspace{1.0cm}}{\vspace{1.0cm}\end{figure}}
\begin{document}
\lipsum[1]
\begin{MyFigure}[h!]
    \centering
    \includegraphics[width=5cm,height=2cm]{foo}
    \caption{Figure: foo}
\end{MyFigure}
\lipsum[2]
\end{document}
  • 4
    You should not add \vspace at the beginning or ending of every figure because it would add this space also, if the figure moves e.g. to a float page or a top or bottom placed figure. If you want to change the vertical distance before and after here placed figures change \intextsep. – Schweinebacke Mar 29 '17 at 10:03
  • Yes, I know this solution with \intexsep. But in my case I need exactly what I asked for, because I need to make some more changes with the figure environment. So, is it possible to change the existing figure environment like the one I quoted in my question? – Benjamin1956 Mar 29 '17 at 11:52
  • If you want other changes you should ask for other changes. And yes, you can patch existing macros and therefore environments using, e.g., xpatch. Nevertheless, I would not recommend to use this to add vertical space before or after figures. – Schweinebacke Mar 29 '17 at 11:56

0 Answers0