Add border for an image (figure) in LaTeX

In this tutorial, I will show you all of the methods to add a border for an image in LaTeX.

Add a border for an image with \fbox

If you want a simple black border around the image, you can use the \fbox like this.

\fbox{\includegraphics[<option>]{<file>}}

Also, you can set the border width and the distance between the image and border with these options.

\setlength{\fboxrule}{<length>} % for border width
\setlength{\fboxsep}{<length>} % distance between the image and border

Take a look.

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\section*{Image with simple border}

\fbox{\includegraphics[width= 0.5\textwidth]{CodeSpeedy-Logo.png}}

\section*{Image with a little bit of customized border}

\setlength{\fboxsep}{20pt}%
\setlength{\fboxrule}{3pt}%
\fbox{\includegraphics[width= 0.5\textwidth]{CodeSpeedy-Logo.png}}

\end{document}

Output:

image with border.

Add a border for an image with \fcolorbox

With the \fcolorbox command, you can add colors on the border and background. Also, you can customize the border width and distance between the image and border.

\setlength{\fboxrule}{<length>}
\setlength{\fboxsep}{<length>}
\fcolorbox{<border-color>}{<background-color>}{\includegraphics[<option>]{<file>}}
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor} % To use colors
\begin{document}

\section*{Image with colored border}

\fcolorbox{red}{yellow}{\includegraphics[width= 0.5\textwidth]{CodeSpeedy-Logo.png}}

\section*{Image with customized and colored border}

\setlength{\fboxrule}{3pt}
\setlength{\fboxsep}{20pt}
\fcolorbox{blue}{lime}{\includegraphics[width= 0.5\textwidth]{CodeSpeedy-Logo.png}}

\end{document}

Output:

image with colored border.

Add a border for an image with \tcbox

You can also use the \tcbox command provided by the tcolorbox package.

\tcbox[boxsep=<length>, boxrule=<length>, 
colframe=<border-color>, colback=<background-color>]
{\includegraphics[<option>]{<file>}}

You can also use the sharp corners option in the \tcbox[] command to get a cornered border.

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor} % To use colors
\usepackage{tcolorbox}
\begin{document}

\section*{Image with rounded corner border using tcolorbox}

\tcbox{\includegraphics[width= 0.5\textwidth]{CodeSpeedy-Logo.png}}

\section*{Image with rounded corner and colored border}

\tcbox[colframe=brown, colback=lime]{\includegraphics[width=0.5\textwidth]{CodeSpeedy-Logo.png}}

\section*{Image with cornered and colored border}

\tcbox[sharp corners, colframe=brown, colback=lime!30!black, boxsep=20pt, boxrule=3pt]{\includegraphics[width=0.5\textwidth]{CodeSpeedy-Logo.png}}

\end{document}

Output:

 

image with colored and rounded border.

Leave a Reply

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