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


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:

  % 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}%

  % box register 0 is a local scratch register
  % The height and depth of the box are increased.
  \ht0=\dimexpr\ht0 + 10pt\relax
  \dp0=\dimexpr\dp0 + 10pt\relax


Related Question