How to add borders, boxes and frames around figures(images) in LaTeX?

By adding a border or frame to the figure, the visualization of documents becomes more beautiful and clearer.

In LaTeX, there are multiple ways to add a border or frame around a figure. I’ll explain a couple of common approaches.

Use fbox command to add borders around the figure

The \fbox command can be used to create a simple rectangular frame around a figure. Here’s an example

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{lipsum,graphicx}
\begin{document}
\section*{Without border}
\lipsum[1][1-3]
\begin{figure}[ht]
    \centering
    \includegraphics[width=1\textwidth,height=.4\textwidth]{figure_07.jpeg}
    \caption{Without border}    
\end{figure}
\section*{Add simple border}
\lipsum[2][1-3]
\begin{figure}[ht]
    \centering
    \fbox{\includegraphics[width=.98\textwidth,height=.4\textwidth]{figure_07.jpeg}}
    \caption{With simple border}    
\end{figure}
\end{document}

Output :

If you want to add some style to the box, you can use \setlength and \fboxsep commands to adjust padding inside the box, and you can change the line width using \fboxrule command.

\setlength{\fboxsep}{10pt} % Adjust the padding
\setlength{\fboxrule}{2pt} % Adjust the border width
\documentclass[11pt]{article}
\usepackage{graphicx,xcolor,subfig}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\begin{figure}[ht]
    \centering
    \setlength{\fboxsep}{15pt} 
    \setlength{\fboxrule}{5pt}
    \fbox{\includegraphics[width=.96\textwidth,height=.4\textwidth]{figure_07.jpeg}}
    \caption{Add padding around border}
\end{figure}
\section*{Add border width and padding}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Dictum fusce ut placerat orci nulla pellentesque dignissim enim. Sed nisi lacus sed viverra tellus in hac.
\begin{figure}[htb]
   \centering
   \setlength{\fboxsep}{10pt} 
   \setlength{\fboxrule}{3pt}
   \subfloat[First subfigure]{\fbox{\includegraphics[width=.36\linewidth]{figure_07.jpeg}}}\hspace{15px}
   \subfloat[Second subfigure] {\fbox{\includegraphics[width=.36\linewidth]{figure_06.jpeg}}}
   \caption{Add padding around box}
\end{figure}
\end{document}

Output :

In this example, \fboxsep is set to 10pt, which increases padding inside the box, and \fboxrule is set to 3pt, which increases line width of the box. You can adjust these values to achieve the desired style for your box.

Using the adjustbox package

adjustbox allows for more advanced framing options. You can use \adjustbox command with the frame option.

Use frame option

This provides a framed image, and you can customize the frame further using options like border width, inner margin, and outer margin. For example

\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{graphicx,lipsum}
\usepackage[margin=1.5cm]{geometry}
\usepackage{adjustbox}
\begin{document}
\begin{figure}[htb]
 \centering
 \adjustbox{width=.43\textwidth,height=.36\linewidth,frame=2pt .5cm}{\includegraphics{figure_06.jpeg}}\hfill
 \adjustbox{width=.43\textwidth,height=.38\linewidth,frame=8pt 0cm}{\includegraphics{figure_08.jpeg}}
 \caption{Your caption}
\end{figure}

\lipsum[1][1-3]

\begin{figure}[htb]
 \centering
 \adjustbox{width=.28\linewidth,frame=2pt 10pt}{\includegraphics{figure_03.jpeg}}\hfill
 \adjustbox{width=.28\linewidth,frame=2pt 8pt}{\includegraphics{figure_04.jpeg}}\hfill
 \adjustbox{width=.28\linewidth,frame=1pt 10pt}{\includegraphics{figure_05.jpeg}}
 \caption{Your caption}
\end{figure}
\end{document}

Output :

Use cfbox option

You can also configure with other options such as cfbox to set border color. And use of cfbox is very similar to frame. But, color argument will be passed along with it.

\documentclass{article}
\usepackage{xcolor}
\usepackage[margin=1.5cm]{geometry}
\usepackage{graphicx,lipsum}
\usepackage{adjustbox}
\begin{document}
\begin{figure}[htb]
 \centering
 \adjustbox{width=.98\textwidth, height=.4\linewidth, cfbox=purple 5pt 0cm}{\includegraphics{figure_07.jpeg}}
 \caption{Your Caption}
\end{figure}

\lipsum[1][1-5]

\begin{figure}[htb]
 \centering
 \adjustbox{width=.27\textwidth, cfbox=blue 3pt 0pt}{\includegraphics{figure_03.jpeg}}\hfill
 \adjustbox{width=.27\textwidth, cfbox=blue 3pt 6pt}{\includegraphics{figure_05.jpeg}}\hfill
 \adjustbox{width=.27\textwidth, cfbox=orange 4pt 0pt}{\includegraphics{figure_06.jpeg}}
 \caption{Your Caption}
\end{figure}
\end{document}

Output :

Use tcolorbox package for tcbox

Our next and most popular method is the tcolorbox package. This is the most used package of box. Among these many types of styles are defined.

Not only for figures, any type of style box is possible with this package.

colframe=color % For border color
colback=color % For background color
boxrule=length % add border width
boxsep=length % add padding
center % alignment
\documentclass[11pt]{article}
\usepackage{graphicx,lipsum,xcolor}
\usepackage[margin=1.5cm]{geometry}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{figure}
 \centering \tcbox[colframe=orange,colback=orange!50,boxsep=5px,boxrule=3px]{\includegraphics[width=.9\textwidth,height=.4\linewidth]{figure_06.jpeg}}
 \caption{Caption}
\end{figure}

\lipsum[2][1-4]
\vspace{10px}

 \tcbox[sharp corners, center, boxsep=5mm, boxrule=2px,colframe=black!50!green, colback=gray!80!green]
 {\includegraphics[width=.42\textwidth]{figure_08.jpeg} \hspace{1cm}
 \includegraphics[width=.42\textwidth]{figure_07.jpeg} }

\end{document}

Output :

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *