6

I'm trying to have a bounding box around the following figure:

\begin{figure}[htp]
\begin{center} 
\subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{noerror-process}}
\subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{synerror-process}} \\
\subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{deadlock-process}}
\subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{lacksync-process}}
\end{center} 
\caption{Different kinds of errors occuring in InFlux Processes}
\label{processes}
\vspace*{-0.65cm}
\end{figure}

Can you please help?

4

2 Answers 2

9

The following example shows possibilites with the package framed, tcolorbox and adjustbox.

enter image description here enter image description here enter image description here

\listfiles
\documentclass[demo]{article}
\usepackage{framed}
\usepackage{tcolorbox}
\usepackage{adjustbox}

\usepackage[]{graphicx}
\usepackage{subfigure}
\begin{document}
\section{Package \texttt{frame}}

\begin{figure}[!htp]
\begin{framed}
\centering
\subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{noerror-process}}\qquad
\subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{synerror-process}}

\subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{deadlock-process}}\qquad
\subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{lacksync-process}}
\caption{Different kinds of errors occuring in InFlux Processes}
\end{framed}
\end{figure}
\clearpage
\section{Package \texttt{tcolorbox}}

\begin{figure}[!htp]
\begin{tcolorbox}
\centering
\subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{noerror-process}}\qquad
\subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{synerror-process}}

\subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{deadlock-process}}\qquad
\subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{lacksync-process}}
\caption{Different kinds of errors occuring in InFlux Processes}
\end{tcolorbox}
\end{figure}
\clearpage
\section{Package \texttt{adjustbox}}

\begin{figure}[!htp]
\begin{adjustbox}{minipage=\linewidth,frame}
\centering
\subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{noerror-process}}\qquad
\subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{synerror-process}}

\subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{deadlock-process}}\qquad
\subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{lacksync-process}}
\caption{Different kinds of errors occuring in InFlux Processes}
\end{adjustbox}
\end{figure}

\end{document}
6

There are several ways to add a frame around such elements (note that bounding box and box in general do mean something else with LaTeX, i.e. do not imply a drawn line).

The simplest way is to use the adjustbox package:

\documentclass{IEEEtran}

\usepackage{subfigure}
\usepackage{adjustbox}

\usepackage{blindtext}% for dummy text only

\begin{document}
\blindtext

\begin{figure}[htp]
\begin{adjustbox}{varwidth=\textwidth,fbox,center}
    \subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{example-image-a}}
    \subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{example-image-b}} \\
    \subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{example-image-c}}
    \subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{example-image}}
\end{adjustbox}
\caption{Different kinds of errors occuring in InFlux Processes}
\label{processes}
%\vspace*{-0.65cm}
\end{figure}

\blindtext
\end{document}

Result


You can also use varwidth and \fbox{..} directly to avoid the need for an extra package:

\documentclass{IEEEtran}

\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{varwidth}

\usepackage{blindtext}% for dummy text only

\begin{document}
\blindtext

\begin{figure}[htp]
\centering
\fbox{\begin{varwidth}{\textwidth}
    \subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{example-image-a}}
    \subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{example-image-b}} \\
    \subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{example-image-c}}
    \subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{example-image}}
\end{varwidth}}
\caption{Different kinds of errors occuring in InFlux Processes}
\label{processes}
%\vspace*{-0.65cm}
\end{figure}

\blindtext
\end{document}

Finally, you can also avoid the varwidth package if you are willing to calculate the required width yourself. Then you can use minipage directly. This is needed in order to box the content for the frame while still allowing for line breaks:

\documentclass{IEEEtran}

\usepackage{subfigure}
\usepackage{graphicx}

\usepackage{blindtext}% for dummy text only

\begin{document}
\blindtext

\begin{figure}[htp]
\centering
\fbox{\begin{minipage}{3.05in}%
    \subfigure[Process with no error]{\label{noerror}\includegraphics[width=1.5in]{example-image-a}} 
    \subfigure[Process with syntactic  errors (connector having multiple incoming edges and presence of hanging node)]{\label{synerror}\includegraphics[width=1.5in]{example-image-b}} \\
    \subfigure[Process with deadlock]{\label{deadlock}\includegraphics[width=1.5in]{example-image-c}} 
    \subfigure[Process with lack of synchronization]{\label{lacksync}\includegraphics[width=1.5in]{example-image}}
\end{minipage}}
\caption{Different kinds of errors occuring in InFlux Processes}
\label{processes}
%\vspace*{-0.65cm}
\end{figure}

\blindtext
\end{document}

There are also other packages for this, e.g. mdframed.

1
  • 1
    What should I do if I want to add a frame around only the subfigures, but not around the full figure?
    – Imran
    Dec 25, 2020 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .