5

I am trying to redefine the command includegraphics to add vertical space below and after my image (I am not using the figure environment since I need to place my images quite carefully.)

I was trying something like below but that doesnt work. Any suggestions?

  \renewcommand{\includegraphics}{\vspace*{3pt}\includegraphics\vspace*{3pt}}
  • 1
    It's not difficult to redefine the macro. However, what's the motivation to redefine such a widely used macro? Maybe you can provide a small full example to explain why you need this. – Leo Liu Nov 4 '13 at 10:41
  • 1
    What is wrong with tweaking \floatsep, \textfloatsep, and \intextsep? As pointed out above, I fail to get the motivation. – Masroor Nov 4 '13 at 10:44
8

I would use the trim option to enlarge the image vertically. You can use \setkeys to do it globally:

\documentclass{scrartcl}
\usepackage{graphicx,lipsum}

\begin{document}
\lipsum[1]

\includegraphics[scale=0.5]{example-image-A}%without space

\lipsum[1]

\newpage 

\lipsum[1]

\includegraphics[trim=0pt -1cm 0pt -1cm,scale=0.5]{example-image-A}%with more space

\lipsum[1]

\newpage

\setkeys{Gin}{trim=0pt -1cm 0pt -1cm}

\lipsum[1]

\includegraphics[scale=0.5]{example-image-A}

\lipsum[1]
\end{document}
  • how many people actually knwo the keyspace for say trim? – daleif Nov 4 '13 at 11:30
  • @daleif: Sorry I don't understand the question. Do you mean the order of the values? – Ulrike Fischer Nov 4 '13 at 11:46
  • Sorry, didn't notice the actual \setkeys in the example. Was just referring to the fact that in order to use \setkeys one need to know the proper value for the first argument, something users usually do not. – daleif Nov 4 '13 at 14:04
3

This uses the \addvbuffer service routine from the verbatimbox package to condition the \includegraphics with, in this MWE, an extra 12pt above and 8pt below the second image.

\documentclass{article}
\usepackage{verbatimbox}
\usepackage[demo]{graphicx}
\begin{document}
without using the figure environment

{\centering
\includegraphics[width=2in]{test-image}
\par}

this is the default spacing.  But with \verb|\addvbuffer|,

{\centering
\addvbuffer[12pt 8pt]{\includegraphics[width=2in]{test-image}}
\par}

the gap above and below the image can be tailored
\end{document}

enter image description here

While one could redefine \includegraphics, I would strongly recommend against it. If adding the text were too onerous for each image, one could define a \myincludegraphics to do this, without tampering with the original.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.