3

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

4

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

2

Frame separation cannot be set in each side. Round the image also with a \parbox, then you can add any vertical (or horizontal) space around the image.

mwe

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\fbox{\parbox{5cm}{\bigskip%
\includegraphics[width=\linewidth]{example-image}\bigskip}}
\end{document}

A bit overkill for a simple frame, but alternatively, you can use longfbox:

mwe2

\documentclass{article}
\usepackage{longfbox}
\fboxset{rounded,border-color=red,padding-top=6pt,padding-bottom=6pt}%
\usepackage{graphicx}
\begin{document}
\lfbox{\includegraphics[width=.4\linewidth]{example-image}}
\end{document}

Or tcolorbox, or mdframed ...

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.