1

When I make an edge opaque (using tikz-network) the label becomes opaque. How can I adjust the opacity of the label independently for edges?

In the following figure $\frac{3}{4}\epsilon$ is opaque.

Opaque Edge Label

This question is close to the one asked here: How to change fill opacity without affecting the angle label?

The following code reproduces the image above:

\documentclass[preview]{standalone}
\usepackage{tikz-network}

\begin{document} \begin{center} \begin{tikzpicture} \useasboundingbox (0,0) rectangle (4,2); \Vertex[x=0.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pOne} \Vertex[x=1.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pTwo} \Vertex[x=2.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pThree} \Vertex[x=3.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFour} \Vertex[x=4.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFive} \Edgecolor=red,opacity=0.5(pTwo) \Edgecolor=red,opacity=0.5(pThree) \Edgecolor=red,opacity=0.5(pFour) \Edgecolor=red,opacity=0.5(pFive) \Edgecolor=red,opacity=0.25,bend=-45(pThree) \Edgecolor=red,opacity=0.25,bend=45(pFour) \Edgecolor=red,fontcolor=black,opacity=0.25, bend=-45,label={$\frac{3}{4}\epsilon$}(pFive) \end{tikzpicture} \end{center} \end{document}

  • 1
    You can use the color red! 25, instead of opacity = 0.25, because you use it to get that color, not to use transparency. try \Edge[color=red!25,fontcolor=black, bend=-45,label={$\frac{3}{4}\epsilon$}](pThree)(pFive) – J Leon V. Jul 07 '22 at 17:09
  • You are correct! If you type in an answer ill mark it as correct tomorrow (except if there is a more satisfying answer by then). – Lodin Ellingsen Jul 07 '22 at 17:16
  • In nodes placed in trajectories it is possible to modify the appearance of the label label={[styles_for_label]orientation_in_sexagesimal_degrees:text_label}, but in the case of edges it doesn't work... hmm but maybe somebody knows how to. – J Leon V. Jul 07 '22 at 17:31
  • I would be very interested in why that approach does not work. I tried for a good while using that approach! – Lodin Ellingsen Jul 07 '22 at 17:36
  • tikz-network chose to use their own key val system, i.e. not pgf keys. This makes things very complicated since you cannot use pgf keys in the commands provided by the package. BTW, opacity is different from setting the color to red!25, say, and you will see the difference if you draw the thing over some background where opacity but not the other option provides you with some nontrivial opacity. –  Jul 07 '22 at 18:16

1 Answers1

2

Try this code using the key text opacity

c

\documentclass[preview]{standalone}
\usepackage{tikz-network}

\begin{document}

\begin{center}
\begin{tikzpicture}
    \useasboundingbox (0,0) rectangle (4,2);
    \Vertex[x=0.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pOne}
    \Vertex[x=1.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pTwo}
    \Vertex[x=2.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pThree}
    \Vertex[x=3.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFour}
    \Vertex[x=4.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFive}
    \Edge[color=red,opacity=0.5](pOne)(pTwo)
    \Edge[color=red,opacity=0.5](pTwo)(pThree)
    \Edge[color=red,opacity=0.5](pThree)(pFour)
    \Edge[color=red,opacity=0.5](pFour)(pFive)
    \Edge[color=red,opacity=0.25,bend=-45](pOne)(pThree)
    \Edge[color=red,opacity=0.25,bend=45](pTwo)(pFour)  
    \Edge[style={text opacity = 1, opacity=0.25},color=red,fontcolor=black, bend=-45, label={$\frac{3}{4}\epsilon$}](pThree)(pFive) % changed <<<<<<<<<<<<  
\end{tikzpicture}

\end{center}

\end{document}

Or save some typing by defining tikz styles

\documentclass[preview]{standalone}
\usepackage{tikz-network}

\tikzset{EdgeOp50/.style={% added <<<<<<<<<< text opacity = 1, opacity=0.5, color=red,
}} \tikzset{EdgeOp25/.style={% added <<<<<<<<<< text opacity = 1, opacity=0.25, color=red,
}}

\begin{document}
\begin{center} \begin{tikzpicture} \useasboundingbox (0,0) rectangle (4,2); \Vertex[x=0.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pOne} \Vertex[x=1.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pTwo} \Vertex[x=2.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pThree} \Vertex[x=3.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFour} \Vertex[x=4.0, y=0.75,size=0.4,style={color=red},opacity=0.3,label=$+$]{pFive} \Edgestyle={EdgeOp50}(pTwo) \Edgestyle={EdgeOp50}(pThree) \Edgestyle={EdgeOp50}(pFour) \Edgestyle={EdgeOp50}(pFive) \Edgestyle={EdgeOp25},bend=-45(pThree) \Edgestyle={EdgeOp25},bend=45(pFour)
\Edgestyle={EdgeOp25},fontcolor=black, bend=-45, label={$\frac{3}{4}\epsilon$}(pFive) %
\end{tikzpicture} \end{center} \end{document}

\SetEdgeStyle[TextOpacity=1, Opacity=0.25] can also be used to set a global Edge style.

Simon Dispa
  • 39,141