I know with overpic
you can put text on top of an image, as explained in this question..
I need to add text to the image but I need it placed on top of a white semitransparent rectangle so that it can be seen. The idea is explained in the following picture taken from the link above (think of the solid white rectangle as semitransparent, excuse my poor editing skills).
I tried overlaying text inside a transparent colored box as
\begin{overpic}[width=\linewidth]{image.png}
\put (0, 2.3){ %
\hspace{-0.1pt}\hspace{-5pt}%
\pgfsetfillopacity{0.5}%
\colorbox{white}{%
\parbox{\linewidth}{\pgfsetfillopacity{1}\hspace{25pt}\color{black} image text \hspace{10pt}} }}
\end{overpic}
But the white box surrounding the text surpasses the bonds of the image and I am left with parts of white rectangles on the background (my background is grey). Which is weird cuz both the image, and colorbox are set to linewidth
, if I make the width of the colorbox smaller then it's off centered (using \centering
doesn't do anything).
There has to be a way to place a semitransparent rectangle within the confinements of the image but I don't know how. Thank you for any help you might have!
MWE:
\documentclass[10pt]{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage[percent]{overpic}
\begin{document}
\begin{frame}
\hspace{-15pt}
\begin{minipage}{0.251\linewidth}
\vspace{10pt}
\begin{overpic}[width=\linewidth]{example-image-a}
\put (0, 2.3){ %
\hspace{-0.1pt}\hspace{-5pt}%
\pgfsetfillopacity{0.5}%
\colorbox{white}{%
\parbox{\linewidth}{\pgfsetfillopacity{1}\hspace{25pt}\color{black} text \hspace{10pt}} }}
\put (-1.95, 15.5){%
\hspace{-0.1pt}\hspace{-2.2pt}%
\pgfsetfillopacity{0.5}%
\colorbox{white}{%
\parbox{\linewidth}{\pgfsetfillopacity{1} \color{black}\hspace{1pt} image text } }}
\end{overpic}
\end{minipage}
\end{frame}
\end{document}
Best Answer
overpic
seems to usetikz
, so advertizingtikz
here may be in order. The question how to add something on top of a pic has this nice answer, which may be relevant if you want to see the grid. Otherwise just doAnother way of making text more visible is to use the
contour
package.