I'm working on a figure of a graph with nodes. I put a white transparent box behind the node label using fill=white
and opacity=0.8
and then I tried using text opacity=1.0
so that the text is still readable. The problem is that the node labels, created in a for-loop, end up having 1.0
instead of the correct number. The graph I get and the graph I want are pictured below:
I haven't found any posts relating text opacity
to pgfmathresult
. Here is a MWE of the code I have:
\usepackage{xifthen}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
[
every label/.style={inner sep=0pt, opacity=0.8, text opacity=1.0, fill=white},
cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
\node[cnode=red,label=0:{$\hat y_1$}] (s1) at (6,-1) {};
\node[cnode=red,label=0:{$\hat y_2$}] (s2) at (6,-2) {};
\node at (6,-3) {$\vdots$};
\node[cnode=red,label=0:{$\hat y_K$}] (sK) at (6,-4) {};
\foreach \x in {0,...,4}
{
\pgfmathparse{\x<4 ? \x : "q-1"}
\ifthenelse{\x>0}
{
\node[cnode=gray,label={90:$z_{\pgfmathresult}$}] (h-\x) at (3,{-\x-div(\x,4)+.5}) {};
}
{
\node[cnode=gray,label=90:$1$] (h-0) at (3,0.5) {};
}
\begin{scope}[on background layer]
\draw (h-\x) -- (s1);
\draw (h-\x) -- (s2);
\draw (h-\x) -- (sK);
\end{scope}
}
\node at (3,-3.5) {$\vdots$};
\node[cnode=gray,label=90:$z_{M}$] (h-q) at (3,-5.5) {};
\begin{scope}[on background layer]
\draw (h-q) -- (s1);
\draw (h-q) -- (s2);
\draw (h-q) -- (sK);
\end{scope}
\end{tikzpicture}
\end{document}
Thanks in advanced.