# how to change the background color of a figure in latex

I insert a figure in my latex. But I want to make the background of the figure to be blue. How could I achieve that?

\begin{figure} [t]%[htbp]%[f]

\centering
\includegraphics[width= 0.65\linewidth]{./figs/BFSall.pdf}
\caption{\color{blue}(a) BFSa-kNN; (b) BFSb-kNN.}
\label{implementationBFSKNN}
\end{figure}

• Could you please make your code compilable by adding the documentclass as well as the relevant packages? (See also: minimal working example (MWE)) – leandriis Oct 3 '19 at 8:12
• Could you please also add some clarification: Do you want to change the background color of the actual image that you include (and that is not available to us) or do you want to add a colored back around the image and the caption? – leandriis Oct 3 '19 at 8:17
• Regarding your use of \olor{blue} inside of \caption: If you want to color all captions in your document that way, you might want to use the \caption package in combination with \captionsetup{textfont={color=blue}}. – leandriis Oct 3 '19 at 8:20
• Probably related if your question is about a colored box around the whole figure environment: Frame and background color for all figures or Rounded corner colored box around figure. Related if it is more about changing the actual background color of the image (if it currently is transparent): ADDING white background to an image? – leandriis Oct 3 '19 at 8:21
• it is impossible to say, you could use \fcolorbox to put a blue panel behind the figure, but if the figure is not transparent it will have no effect. If the background within the figure is (say) white rather than transparent you will need to edit the source of the figure. – David Carlisle Oct 3 '19 at 8:26

The mdframed package can add a coloured background if the bg of the pdf is transparent

\documentclass{article}
\usepackage{xcolor,mdframed}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htbp]
\begin{mdframed}[backgroundcolor=blue!50,linecolor=blue!50]
\includegraphics[width=\linewidth]{example-image-a4-landscape.pdf}
\caption{text}
\end{mdframed}
\end{figure}

\begin{figure}[htbp]
\begin{mdframed}[backgroundcolor=blue!50,linecolor=blue!50]
\includegraphics[width=\linewidth]{example-image-a4-landscape.pdf}
\end{mdframed}
\caption{text}
\end{figure}

\end{document}

• Thanks. This is what I wanted. – BigTree Oct 3 '19 at 23:18