# Issue with opacity option in tcolorbox

The following

\documentclass[10pt]{article}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}

\newtcbox{\mytransparentbox}{blank, on line, opacitytext=0.4}

\begin{document}
\includegraphics[scale=0.1]{engine}
\mytransparentbox{\includegraphics[scale=0.1]{engine}}
\end{document}


gives

.

The used pdf file is available here.

I would like the inside of the wheel to be white (or fully transparent). Is there any fix?

PS: The package transparent does not work in my case (because of package conflict I guess), so I'm looking for a solution not using it.

PPS: I am looking for a solution that does not require to modify the images (for instance to convert it to a png image).

• Does your PPS exclude solutions that fix the problems in the pdf but still has the image as pdf? – samcarter_is_at_topanswers.xyz Aug 8 '18 at 18:28
• Not necessarily. I have created the pdf with Sketch – Colas Aug 9 '18 at 7:50

This is a variation of Ulrike's code to include the white rectangle in tcbox options. It's possible to include graphics commands after the text with finish option (section 10.9, page 197).

\newtcbox{\mytransparentbox}{blank, on line,
finish={\fill[white, opacity=0.6] (frame.south west) rectangle (frame.north east);}}


And another option could be to apply similar options to a \tcbincludegraphics box. This command (section 11.1, page 251) puts an image included by \includegraphics command inside a tcolorbox. In this case

\tcbincludegraphics[...]{engine}


The complete code with both examples is:

\documentclass[10pt]{article}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}

%Original command with finish option
\newtcbox{\mytransparentbox}{blank, on line, finish={\fill[white, opacity=0.6] (frame.south west) rectangle (frame.north east);}}

%Options for tcbincludegraphics
\tcbset{
mytransparentbox/.style={
blank, hbox, on line,
graphics options={scale=0.1},
finish={\fill[white, opacity=.6]
(frame.south west) rectangle
(frame.north east);}
}
}

\begin{document}
\includegraphics[scale=0.1]{engine}
\begin{tikzpicture}%%%%%% Ulrike's solution
\node[inner sep=0pt] (a){\includegraphics[scale=0.1]{engine}};
\pgfsetfillopacity{0.6}
\fill[white](a.south west)rectangle (a.north east);
\end{tikzpicture}

\mytransparentbox{\includegraphics[scale=0.1]{engine}}
\tcbincludegraphics[mytransparentbox]{engine}
\end{document}


You could place a white rectangle with an opacity over the picture:

\documentclass[10pt]{article}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}
\newtcbox{\mytransparentbox}{blank, on line, opacitytext=0.4}

\begin{document}
\includegraphics[scale=0.1]{engine}

\begin{tikzpicture}
\node[inner sep=0pt] (a){\includegraphics[scale=0.1]{engine}};
\pgfsetfillopacity{0.6}\fill[white](a.south west)rectangle (a.north east);
\end{tikzpicture}

\mytransparentbox{\includegraphics[scale=0.1]{engine}}

\end{document}


First convert the PDF file into a PNG image and then apply the code.

\documentclass[border=4mm]{standalone}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}

\newtcbox{\mytransparentbox}{blank, on line, opacitytext=0.4}

\begin{document}
\includegraphics[scale=0.1]{engine1}
\mytransparentbox{\includegraphics[scale=0.1]{engine1}}
\end{document}

• I cannot convert the pdf file to png... – Colas Aug 8 '18 at 16:42
• @Colas Use this online converter pdf2png.com – Cragfelt Aug 8 '18 at 16:49
• @Colas Did my answer solve your issue? – Cragfelt Aug 8 '18 at 17:16
• Not really, I am looking for an answer that does not require to modify the image. – Colas Aug 8 '18 at 17:37
• I think a PDF has not a background. – Colas Aug 8 '18 at 17:42

A non-latex approach:

The syntax of the pdf file looks a bit strange. Instead of including the shapes directly, it includes larger squares which are clipped to form the gears.

The problem with the transparency can be circumvented if the inner circle is filled in white, which can be done by editing the pdf in e.g. inkscape.

I uploaded the fixed version of the pdf to https://github.com/colasbd/bug_opacity_tcolorbox/blob/6893ed5d0222596010310882a17986fb63ce19ae/engine_fix.pdf

• Thank you! I have created the PDF in sketch – Colas Aug 9 '18 at 8:37