在传单文档类中使用 tikz 的不透明度

在传单文档类中使用 tikz 的不透明度

我正在使用 leaflet 文档类,并希望在 tikz 中使用不透明度选项。最小示例:

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

改变不透明度的值没有效果(“opacity=x” 也是一样)。

答案1

在默认模式下,每页存储在六个保存框中,以将所有页面放在两个有序页面中,这可能会影响不透明度命令,这可能是nocombine模式下工作正常但每页都被裁剪的原因;处理此问题的一种方法是使用透明而不是不透明度命令,但两者彼此不兼容,如果加载透明,tikz 命令不透明度将被忽略或失去效果,但您可以使用透明绘制 tikz 透明元素:

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

它将里面的元素设置{}为定义的透明度值。

在leaflet文档类中使用宏来在nocombine的情况下为每个页面放置背景图像,并且默认情况下很多时候需要使用透明包来淡化这些图像以免隐藏相同颜色的文本部分:

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

因此,您必须使用 tikz 的不透明度,因为您有两个限制,不使用transparent包和模式nocombine;解决此问题的一种方法是在另一个文档中处理绘图并将结果导入主文档。它允许您自由使用 tikz 的所有选项,而不会出现任何兼容性问题,也不会丢失矢量属性和不透明度。但是,如果您需要在导入的 pdf tikz 输入中再次设置透明度,而该输入具有不透明度的对象,则可能会出现一个问题,\transparent 命令将不起作用,这里有一个例子来说明所有问题和解决方案。

结果: 在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[notumble]{leaflet}
\usepackage{tikz}
\usepackage{color}
\usepackage{transparent}
\usepackage{fancyvrb}
\AddToBackground{5}{%  
    \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]
    \AddToBackground{5}{%  
    \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:独立-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:独立-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}

答案2

我发现,如果我使用 XeLaTeX 进行编译,问题就完全消失了。至少对于 LaTeX 来说,这个问题似乎一直存在。对此有什么解释吗?

相关内容