Use opacity from tikz in leaflet documentclass

I am using the leaflet documentclass and want to use the opacity option in tikz. Minimal example:

\documentclass{leaflet}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[fill=red,fill opacity=0.5] (0,0) {TEST};
\end{tikzpicture}
\end{document}


Changing the value of opacity has no effect (same for "opacity=x").

• I’ve had similar problems. The opacity option does work if you use the nocombine option of the leaflet class, but I can’t explain why. Sep 25 '18 at 13:56

In the default mode each page is stored in a six saveboxes to put all in two ordered pages, this could affect the opacity command and that could be the reason that in nocombine mode works without problems, but each page is croped; An option to deal with this ussues is using transparent instead opacity command but both are incompatible with each other, if you load transparent the tikz command opacity is ignored or lose effect, but you could draw tikz transparent elements using transparent:

{\transparent{value_0_to_1}\draw....;   \node...;}


It sets the elements inside {} to the defined transparency value.

In the leaflet document class uses a macro to put background images for each page in the case of nocombine, and for many in the default so many times is needed to use the transparent package to fade these images not to hide part of the text of the same color:

\AddToBackground{page_number}{%
\put(X_coordinate,Y_coodindate ){\transparent{value_0_to_1}\includegraphics[scale=scale_val,angle=rotate_val]{image_file_name}}}


So you will have to use the opacity of tikz you have the two limitations, without using transparent package and in the mode nocombine; One way to deal with this is to work the drawing in another document and import the result into the main document. It allows you to use freely all the options for tikz without any compatibility problems, without loosing vector properties and opacity. But one issue could apear if you need set the transparency again in an imported pdf tikz input that has objets with opacity, the \transparent commant won't work, Here an example to illustrate all the issues and solutions.

RESULT:

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[notumble]{leaflet}
\usepackage{tikz}
\usepackage{color}
\usepackage{transparent}
\usepackage{fancyvrb}
\put(0,-200){\transparent{.07}\includegraphics[scale=3,angle=60]{standalone-tikz-002.pdf}}}

\begin{document}
{\bf Known Issues:}\par
For example including standalone-tikz-001.tex pdf output and trying to set some transparency, it does not work, it respects the opacity in tikz code and ignores transparent value:
\vspace{-\baselineskip}
\begin{scriptsize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
{\transparent{0.25}
\includegraphics[width=0.5\textwidth]{standalone-tikz-001.pdf}
}
\end{Verbatim}
\end{scriptsize}
\vspace{-\baselineskip}
\begin{center}
{\transparent{0.25}
\includegraphics[width=0.5\textwidth,]{standalone-tikz-001.pdf}
}
\end{center}
If the code is rewrited without using opacity and saved in other document:
\vspace{-\baselineskip}
\begin{scriptsize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
%File name: standalone-tikz-002.tex
\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
\draw[fill=lime!\mixcol!blue] (0+\l,0-\l) rectangle ++(4,-1.5);
\node[fill=yellow!\mixcol!red] at (0+\l,0-\l) {TEST};
}
\end{tikzpicture}
\end{document}
\end{Verbatim}
\end{scriptsize}
Transparent value works
\vspace{-\baselineskip}
\begin{scriptsize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
{\transparent{0.25}
\includegraphics[width=0.5\textwidth]{standalone-tikz-002.pdf}
}
\end{Verbatim}
\end{scriptsize}
\begin{center}
{\transparent{0.25}
\includegraphics[width=0.5\textwidth,]{standalone-tikz-002.pdf}
}
\end{center}
Also works for the background...
\vspace{-\baselineskip}
\begin{scriptsize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
\put(0,-200){\transparent{.07}\includegraphics[
scale=3,angle=60]{standalone-tikz-002.pdf}}}
}
\end{Verbatim}
\end{scriptsize}

\newpage
Page2
\newpage
Page3
\newpage
Page4
\newpage
{\bf Default mode opacity Issue}:\par  Here a draging using Tikz code in the main document, that uses \verb+opacity+ command, without class option \verb+nocombine+, the result ignores \verb+opacity+ command, that also is ignored in other cocument classes if \verb+\usepackage{transparent}+ is loaded.\\

\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
\draw[fill=lime!\mixcol!blue,opacity=\x] (0+\l,0-\l) rectangle ++(4,-1.5);
\node[fill=yellow!\mixcol!red,fill opacity=1.2-\x,text opacity=1] at (0+\l,0-\l) {TEST};
}
\end{tikzpicture}

{\bf Using transparent:}\par
Another example of a Tikz code in the main document, using \verb+\transparent{value_0_to_1}+ , requires two compilations... and also the opacity commands still without effect but each tikz drawing has  transparency.\\

\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
{\transparent{\x}
\draw[fill=lime!\mixcol!blue,opacity=\x] (0+\l,0-\l) rectangle ++(4,-1.5);
\node[fill=yellow!\mixcol!red,fill opacity=1.2-\x,text opacity=1] at (0+\l,0-\l) {TEST};
}
}
\end{tikzpicture}

\newpage
An option using a good practice to draw a tikz picture in standalone document class where you can use all the options for tikz without any compatibility problem.
\begin{scriptsize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
%File name: standalone-tikz-001.tex
\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}
{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
\draw[
fill=lime!\mixcol!blue,
opacity=\x
](0+\l,0-\l) rectangle ++(4,-1.5);
\node[
fill=yellow!\mixcol!red,
fill opacity=1.2-\x,
text opacity=1
] at (0+\l,0-\l) {TEST};
}
\end{tikzpicture}
\end{document}
\end{Verbatim}
\end{scriptsize}
Then include it in the main document using \verb+graphicx+ package:
\begin{footnotesize}
\begin{Verbatim}[tabsize=2,frame=lines,framerule=0.5pt]
\includegraphics[width=\textwidth]{standalone-tikz-001.pdf}
\end{Verbatim}
\end{footnotesize}
\includegraphics[width=\textwidth]{standalone-tikz-001.pdf}

\end{document}


SUB1: standalone-tikz-001.tex

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[tikz,border=5pt]{standalone}

\begin{document}
\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
\draw[fill=lime!\mixcol!blue,opacity=\x] (0+\l,0-\l) rectangle ++(4,-1.5);
\node[fill=yellow!\mixcol!red,fill opacity=1.2-\x,text opacity=1] at (0+\l,0-\l) {TEST};
}
\end{tikzpicture}
\end{document}


SUB2: standalone-tikz-002.tex

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \x [count=\l from 0] in {1,0.8,...,0.2}{
\pgfmathparse{int(\x*100)}
\edef\mixcol{\pgfmathresult}
\draw[fill=lime!\mixcol!blue] (0+\l,0-\l) rectangle ++(4,-1.5);
\node[fill=yellow!\mixcol!red] at (0+\l,0-\l) {TEST};
}
\end{tikzpicture}
\end{document}

• If I compile your suggested document then nothing is transparent for me... Could this be a reason of the used LaTeX version? I use TeXLive2017...
– Arne
Sep 27 '18 at 7:23
• Have you compiled two times? that is needed to get transparency using transparent package... Sep 27 '18 at 12:56
• Yes, I did and it looks like this: i.stack.imgur.com/B3L1s.png
– Arne
Sep 28 '18 at 8:07
• To compile I use pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6745 64-bit), LaTeX2e <2018-04-01> patch level 5, the first run output register has a waring that says: Rerun to get transparencies right, and in the second run there are only badbox registers...; It cant work with XeLatex or LuaLatex, only works with PDFLatex.. Sep 28 '18 at 13:17
• So, I updated my LaTeX. Now, I compile with pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018), LaTeX2e <2018-04-01> patch level 2. I get also the warning "Package transparent Warning: Rerun to get transparencies right." After the second compile the image is still as before: i.stack.imgur.com/fkQQo.jpg
– Arne
Oct 1 '18 at 14:32

I found out that if I compile with XeLaTeX the issue is completely gone. It seems to be persistent for at least LaTeX. Any explanations on that?