[Tex/LaTex] Add a specific space on top and bottom of a fbox

fboxframedgraphicsspacing

I have a figure which rounded by fbox, I am wondering how can I add a space only at the top and bottom of the image since \setlength{\fboxsep}{6pt}add space around the whole figure.

Thank you

Best Answer

Two methods for adding a top and bottom padding inside a \fbox:

  • If the figure is an image included by \includegraphics then option trim can be used to add the padding.

  • A general method puts the contents of \fbox in a box and increases its height and depth.

Example file:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\setlength{\fboxsep}{0pt}
\fbox{%
  % Negative trim values add space.
  % The amount is scaled with the image (scaled here by option "width").
  \includegraphics[width=60pt, trim=0 -40pt 0 -40pt]{example-image.pdf}%
}

\fbox{%
  % box register 0 is a local scratch register
  \sbox{0}{\includegraphics[width=60pt]{example-image.pdf}}%
  % The height and depth of the box are increased.
  \ht0=\dimexpr\ht0 + 10pt\relax
  \dp0=\dimexpr\dp0 + 10pt\relax
  \usebox{0}%
}
\end{document}

Result

Related Question