当使用选项 [transparency group]
和[opacity]
并且图像在范围环境中移动时堆叠在一起,是否可以准确显示相同的图像而不改变颜色?
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}[transparency group, opacity=0.5]
\node[rounded corners=20mm,fill=red,minimum size=4cm] {} ;
\end{scope}
\begin{scope}[transparency group, opacity=0.5, xshift=5mm, yshift=5mm]
\node[rounded corners=20mm,fill=red,minimum size=4cm] {} ;
\end{scope}
\begin{scope}[transparency group, opacity=0.5, xshift=10mm, yshift=10mm]
\node[rounded corners=20mm,fill=red,minimum size=4cm] {} ;
\end{scope}
\end{tikzpicture}
\end{document}
答案1
受到@cfr 回答(+1)的鼓励,让我将我的评论扩展为一个答案:
- 一个案例,那么所有圆圈都有相同的颜色(这很容易,只需删除
opacity=0.5
选项):
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 5mm and 5mm, on grid,
N/.style = {circle, minimum size=4cm, fill=red!50,
node contents={}}
]
\node (n1) [N];
\node (n2) [N, above right=of n1];
\node (n3) [N, above right=of n2];
\node (n4) [N, above right=of n3];
\end{tikzpicture}
\end{document}
- 如果您喜欢看到被其他圆圈覆盖的圆圈,并看到它们的颜色,则需要为节点添加透明度,例如通过`opacity = 0.5。在这种情况下,编译结果如您所见:
为此你不需要使用transparency group
:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 5mm and 5mm, on grid,
N/.style = {circle, minimum size=4cm, fill=red, opacity=0.5,
node contents={}}
]
\node (n1) [N];
\node (n2) [N, above right=of n1];
\node (n3) [N, above right=of n2];
\node (n4) [N, above right=of n3];
\end{tikzpicture}
\end{document}
答案2
我猜你想要的结果不是你堆叠透明物体时所期望的结果,而是你将透明度应用于不规则形状时所期望的结果。
\documentclass[tikz]{standalone}
% shamelessly borrowing Zarko's code to avoid trying vainly to square circles (or circle squares?) at https://tex.stackexchange.com/questions/694688/tikz-accurate-colors-with-shifting-in-scope-environments-while-using-transpare#comment1724430_694688
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[ node distance = 5mm and 5mm, on grid, N/.style = {circle, minimum size=4cm, fill=red, node contents={}} ]
\begin{scope}[transparency group,opacity=.5]
\node (n1) [N]; \node (n2) [N, above right=of n1]; \node (n3) [N, above right=of n2];
\end{scope}
\end{tikzpicture}
\end{document}