4

I have an image in my document and I am trying to add a space between the frame of the image and the image itself. I tried to search but I didn't find results serve the purpose. The following code to insert an image:

    \begin{figure}[H]
            \centering
            \frame{\includegraphics [height=12cm,width=14cm]{SystemDesign}}
            \caption{Image}
            \label{fig:SystemDesign}
    \end{figure}

But my figure installed from a software that crop it exactly around the entities included in the image, I tried different solutions and the last one is to add a space between the image and the frame in LaTeX. So I am not sure if there is a way to approach that?

  • 1
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Stefan Pinnow Mar 28 '18 at 14:17
  • @StefanPinnow I added the code, thank you. – User505 Mar 28 '18 at 14:24
2

Using \frame is the wrong way as it does not add any separation between the content and the frame. If you want to have a separation then use \fbox instead where the separation can be adjusted using the length \fboxsep. The frame line width is adjustable by the length \fboxrule.

However, an easier way is to load the adjustbox package with the export option and simply use the fbox key with two space separated arguments for the line width and separation distance.

Then you should replace \centering with the center key so the image is also centered without warnings if its width is larger than the text width.

\begin{figure}[H]
        \includegraphics [height=12cm,width=14cm,fbox=0.5pt 10pt,center]{example-image}
        \caption{Image}
        \label{fig:SystemDesign}
\end{figure}

Note that you can generate the whole figure construct including the H placement with a single adjustbox command:

\adjustimage{height=12cm,width=14cm,fbox=0.5pt 10pt,center,captionbelow={Image},label={fig:mylabel},nofloat=figure}{example-image}

This then needs the adjustbox package but not necessarily the export option any more.


Full code example:

\documentclass{article}
\usepackage{graphicx}% also loaded by adjustbox
\usepackage[export]{adjustbox}
\usepackage{lipsum}% just for example text
\begin{document}
\lipsum

    \begin{figure}
            \includegraphics [height=12cm,width=14cm,fbox=0.5pt 10pt,center]{example-image}
            \caption{Image}
            \label{fig:SystemDesign}
    \end{figure}

\lipsum
\clearpage
\lipsum

\adjustimage{height=12cm,width=14cm,fbox=0.5pt 10pt,center,captionbelow={Image},label={fig:mylabel},nofloat=figure}{example-image}

\lipsum
\end{document}
2

This is will do the job:

\begin{figure}[H]

                \centering
                \setlength{\fboxsep}{10pt}%
                \setlength{\fboxrule}{0.5pt}%
                \fbox{\includegraphics[height=12cm,width=15.5cm]{SystemDesign}}
                \caption{Image}
                \label{fig:SystemDesign}
\end{figure}
  • 1
    The code does not use any feature of adjustbox, so the package is actually not needed. There is a way to do this with adjustbox with less number of lines, though. – Martin Scharrer Mar 29 '18 at 7:09
  • I will edit the code, thank you @MartinScharrer – User505 Mar 29 '18 at 7:53

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.