Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Welcome to TeX.sx! Note that we like to see minimal working example (MWE) which are complete and compilable, not just code snippets. This gives people the possibility to easily compile your example and to add and test their solution. –  Martin Scharrer May 13 '12 at 12:52
    
You can use the package tcolorbox or framed. –  Marco Daniel May 13 '12 at 12:56
    
Should the caption be inside the frame or outside? –  Martin Scharrer May 13 '12 at 13:09
1  
Also see Should I use center or centering for figures and tables? to learn why you should use \centering instead of center. –  Martin Scharrer May 13 '12 at 13:10
add comment

2 Answers

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}
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.