我有三个想要相互叠加的对象:背景图片上的一些文本,使用圆圈创建从白色到透明的径向渐变,以便可以阅读文本。
我不确定是否是因为我的 TeX 引擎(sharelatex.com 中的 PdfLaTeX 和 LaTeX),但由于某种原因,我无法让圆圈与背景图像一起淡出为透明。
这是代码:
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{graphics}
\usetikzlibrary{arrows,positioning,trees,fadings}
\pgfdeclareradialshading{myshading}{\pgfpointorigin}{%
color(0mm)=(white);
% color(5mm)=(pgftransparent!10);
% color(8mm)=(pgftransparent!20);
color(15mm)=(pgftransparent!100)
}
\pgfdeclarefading{myfading}{\pgfuseshading{myshading}}
\tikzset{
>=stealth',
punkt2/.style={
rectangle,
rounded corners,
dashed,
draw=black, thick,
text width=7em,
minimum height=2em,
text centered},
level 1/.style={sibling angle=45, level distance=3.5cm},
edge from parent/.style= {draw=none},
}
\begin{document}
\begin{tikzpicture}
\node[opacity=0.5] (img2) at (0,7.5) {\includegraphics[height=18cm]{greenelephant}};
\shade[shading=myshading] (0,7.5) circle (5.5);
\coordinate (main2) at (0,7.5) [counterclockwise from=90]
child { node[punkt2, text width=10em, solid] (a1) {State 0}}
child { node[punkt2] (a2) {State 1}}
child { node[punkt2] (a3) {State 2}}
child { node[punkt2] (a4) {State 3}}
child { node[punkt2, text width=10em, solid] (a5) {State 4}}
child { node[punkt2] (a6) {State 5}}
child { node[punkt2] (a7) {State 6}}
child { node[punkt2] (a8) {State 7}};
\draw[->] (a1) edge[bend right=10] (a2);
\draw[->] (a2) edge[bend right=10] (a3);
\draw[->] (a3) edge[bend right=10] (a4);
\draw[->] (a4) edge[bend right=10] (a5);
\draw[->] (a5) edge[bend right=10] (a6);
\draw[->] (a6) edge[bend right=10] (a7);
\draw[->] (a7) edge[bend right=10] (a8);
\draw[->] (a8) edge[bend right=10] (a1);
\node at (0,7.5) (label2) {\textsc{Cycle}};
\end{tikzpicture}
\end{document}
而不是命令
\shade[shading=myshading] (0,7.5) circle (5.5);
我也尝试过这个
\pgfsetfading{myfading}{} \fill[white] (0,7.5) circle (5);
但是这个命令似乎中断了其余的处理,因为我甚至没有得到圆圈或文本。
答案1
类似这样的?我怕我没有大象,所以我用老虎代替了。
或者 (编辑) 像这样?
\documentclass[margin=10pt,tikz,multi]{standalone}
\usetikzlibrary{arrows.meta,positioning,trees,fadings}
\pgfdeclareradialshading[radialcolour1,radialcolour2,radialcolour3]{myshading}{\pgfpointorigin}{%
color(0)=(radialcolour1);
color(15bp)=(radialcolour2);
color(50bp)=(radialcolour3)
}
\tikzset{%
radial inner colour/.code={
\colorlet{radialcolour1}{#1}
},
radial mid colour/.code={
\colorlet{radialcolour2}{#1}
},
radial outer colour/.code={
\colorlet{radialcolour3}{#1}
},
radial inner colour=white,
radial mid colour=white!50!black,
radial outer colour=black,
my inner shading/.style={
radial inner colour=#1,
shading=myshading,
},
my mid shading/.style={
radial mid colour=#1,
shading=myshading,
},
my outer shading/.style={
radial outer colour=#1,
shading=myshading,
},
>={Stealth[]},
punkt2/.style={
rectangle,
rounded corners,
dashed,
draw=black,
thick,
text width=7em,
minimum height=2em,
text centered},
level 1/.style={sibling angle=45, level distance=3.5cm},
edge from parent/.style={draw=none},
}
\tikzfading[name=myfading, my inner shading=transparent!100, my outer shading=transparent!0, my mid shading=transparent!0]
\tikzfading[name=myfading2, my inner shading=transparent!0, my mid shading=transparent!25, my outer shading=transparent!100]
\begin{document}
\begin{tikzpicture}
\node [opacity=0.5] (img2) at (0,7.5) {\includegraphics[height=18cm]{tiger}};
\fill [path fading=myfading, fill=white] (0,7.5) circle (5.5);
\coordinate (main2) at (0,7.5) [counterclockwise from=90]
child { node[punkt2, text width=10em, solid] (a1) {State 0}}
child { node[punkt2] (a2) {State 1}}
child { node[punkt2] (a3) {State 2}}
child { node[punkt2] (a4) {State 3}}
child { node[punkt2, text width=10em, solid] (a5) {State 4}}
child { node[punkt2] (a6) {State 5}}
child { node[punkt2] (a7) {State 6}}
child { node[punkt2] (a8) {State 7}};
\draw[->] (a1) edge[bend right=10] (a2);
\draw[->] (a2) edge[bend right=10] (a3);
\draw[->] (a3) edge[bend right=10] (a4);
\draw[->] (a4) edge[bend right=10] (a5);
\draw[->] (a5) edge[bend right=10] (a6);
\draw[->] (a6) edge[bend right=10] (a7);
\draw[->] (a7) edge[bend right=10] (a8);
\draw[->] (a8) edge[bend right=10] (a1);
\node at (0,7.5) (label2) {\textsc{Cycle}};
\end{tikzpicture}
\begin{tikzpicture}
\node [opacity=0.5] (img2) at (0,7.5) {\includegraphics[height=18cm]{tiger}};
\fill [path fading=myfading2, fill=white] (0,7.5) circle (5.5);
\coordinate (main2) at (0,7.5) [counterclockwise from=90]
child { node[punkt2, text width=10em, solid] (a1) {State 0}}
child { node[punkt2] (a2) {State 1}}
child { node[punkt2] (a3) {State 2}}
child { node[punkt2] (a4) {State 3}}
child { node[punkt2, text width=10em, solid] (a5) {State 4}}
child { node[punkt2] (a6) {State 5}}
child { node[punkt2] (a7) {State 6}}
child { node[punkt2] (a8) {State 7}};
\draw[->] (a1) edge[bend right=10] (a2);
\draw[->] (a2) edge[bend right=10] (a3);
\draw[->] (a3) edge[bend right=10] (a4);
\draw[->] (a4) edge[bend right=10] (a5);
\draw[->] (a5) edge[bend right=10] (a6);
\draw[->] (a6) edge[bend right=10] (a7);
\draw[->] (a7) edge[bend right=10] (a8);
\draw[->] (a8) edge[bend right=10] (a1);
\node at (0,7.5) (label2) {\textsc{Cycle}};
\end{tikzpicture}
\end{document}