1

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}
5
  • 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, 2019 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, 2019 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, 2019 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, 2019 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. Oct 3, 2019 at 8:26

1 Answer 1

1

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}
1
  • Thanks. This is what I wanted.
    – BigTree
    Oct 3, 2019 at 23:18

You must log in to answer this question.

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