3

I want to add some opacity to draw several angles but the arrowheads (-latex and -stealth) are modified with fill opacity option. At the moment, I'm re-drawing all angles twice, with fill options and without, to keep the arrow heads plain.

First : How can I keep the arrowheads without transparency ?

Second : With -latex arrowheads the filled area and the draw lines do not match anymore. There is a small blank between them.

These issues still remain with arrow and arrows.meta libraries.

Here a MWE :

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{angles, quotes, positioning, calc}

\begin{document}
    \begin{tikzpicture}[line width=0.8pt]
        \pgfmathsetmacro{\r}{4}
        \pgfmathsetmacro{\A}{80}
        \pgfmathsetmacro{\B}{150}
        
        \draw[-stealth, line width=0.4pt] (-\r-0.6,0) -- (\r+0.65,0) coordinate[label=above left:x] (X) ;
        \draw[-stealth, line width=0.4pt] (0,-\r-0.6) -- (0,\r+0.65) coordinate[label=below right:y] (Y) ;
        \draw (\r,-1.85*\r) -- (\r,1.85*\r);
        \draw (0,0) coordinate (O) circle(\r);
        %% Valeurs d'angles
        \coordinate (A) at (\A:\r);
        \coordinate (B) at (\B:\r);
        
        %% Représentation des angles
        \pic["$\beta$", draw, blue, fill=blue!30,  angle eccentricity=1.7, angle radius=0.4cm, -stealth, pic text options={xshift=-13pt}] {angle=X--O--B};
        \pic["$\alpha$", draw, teal!70!black, fill=black!30, fill opacity=0.6,  angle eccentricity=1.5, angle radius=0.7cm, -latex, pic text options={text opacity=1}] {angle=X--O--A};
        
        \draw (O) -- (A.center);
        \draw (O) -- (B.center);
        
        \draw[-stealth, line width=0.4pt] (0,0) -- (X);
    \end{tikzpicture}
\end{document}

And here highlighted problems : enter image description here

0

2 Answers 2

5

Just loading the arrows.meta library won't change any arrow tips (except the special >), it provides its own with capitalized words: Stealth and Latex/LaTeX in this case.

Use those, if you want to use the power of arrows.meta or define shortcuts

\tikzset{
  stealth/.tip = Stealth,
  latex/.tip = LaTeX,
}

overwriting the predefined tips.

Your second problem is easily solved by loading the bending library which sets the flex arrow key. (The default is quick which can be set by doing \tikzset{arrows={[quick]}}.)

(Background: The angle library separates the filling and drawing in two separate paths (and on two different layers) which desyncs these two actions. The arrow tip offsets the curve by the tip length on a straight line which leads to this malformed curve.)

For your first problem I offer a new arrow key: fill opacity. Since opacity and filled arrow tips never place nicely together I set this to 1 in the preamble.

I've also added text opacity=1 to the preamble for the angle pic. Seems to be a good default.

By the way, instead of "<label>", pic text options={<options>} you can write "<label>" {<options>} where the braces are even optional if they contain no comma.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, angles, bending, quotes, positioning, calc}
\pgfset{arrow keys/fill opacity/.code=
  \pgfarrowsaddtooptions{\pgfsetfillopacity{#1}}}
\tikzset{arrows={[fill opacity=1]}} % seems right to declare this globally
\tikzset{pics/angle/.append style={/tikz/text opacity=1}}% this, too
\begin{document}
\begin{tikzpicture}[line width=0.8pt]
\pgfmathsetmacro{\r}{4}
\pgfmathsetmacro{\A}{80}
\pgfmathsetmacro{\B}{150}

\draw[-Stealth, line width=0.4pt] (-\r-0.6,0) -- (\r+0.65,0)
  coordinate[label=above left:x] (X) ;
\draw[-Stealth, line width=0.4pt] (0,-\r-0.6) -- (0,\r+0.65)
  coordinate[label=below right:y] (Y) ;
\draw (\r,-1.85*\r) -- (\r,1.85*\r);
\draw (0,0) coordinate (O) circle(\r);
%% Valeurs d'angles
\coordinate (A) at (\A:\r);
\coordinate (B) at (\B:\r);

%% Représentation des angles
\pic["$\beta$",  draw, blue, fill=blue!30,
  angle eccentricity=1.7, angle radius=0.4cm, -Stealth,
  pic text options={xshift=-13pt}] {angle=X--O--B};
\pic["$\alpha$", draw, teal!70!black, fill=black!30, fill opacity=0.6,
  angle eccentricity=1.5, angle radius=0.7cm, -Latex] {angle=X--O--A};

\draw (O) -- (A.center);
\draw (O) -- (B.center);

\draw[-Stealth, line width=0.4pt] (0,0) -- (X);
\end{tikzpicture}
\end{document}

Output

enter image description here

4
  • Nice. Seems to me that opacity and fill opacity could/should have been included arrow options. Sep 24 at 20:22
  • @hpekristiansen I thought there was a discussion about opacity and arrow tips around the topic of transparency groups but I can't find it. The manual states however that “[i]n general, it is a good idea not to add arrow tips to paths that are filled.” Funnily, enough, the angle pic doesn't actually, internally, but by the nature of its definition and how pics work the fill opacity still applies to a path that isn't even filled (but a subpath, the arrow tip, is). It's really an annoying issue, especially with different opacities for stroke and fill. Sep 24 at 20:47
  • Complete answer for solutions, explanations and tips. Thanks ! I understand the internal design inducing the behaviour. Do you know if it is planned to be fixed in the future ? It seems a bit odd to me and I'm not sure it is the desired result. But maybe, like dominoes, a small change to fix it could results in bigger issues for such library of pgf. Anyway, accepted !
    – Piroooh
    Sep 26 at 9:28
  • @Piroooh The angle pic (and its library) was probably the first real pic and was the only that came with PGF/TikZ originally (the newer folding library also provides pics). The code has barely changed since 2013. I would construct the pic very differently although the decoupling of fill and draw has some validity if you're using the pic on the same path on which you're drawing the corner. (I have thoughts on this that are too long for a comment.) Even if it were one path, without bending the arrow would look bad. The opacity thing – see my previous comment. Sep 26 at 12:58
1

A small, mostly off-topic variation of nice @Qrrbrbirbel answer (+1) which already solve your main problem. In my MWE are changed:

  • definitions of arrows
  • definition for pic style is common
  • a wee bit shorter code

All for exercise and joy ...

\documentclass[tikz,
               margin=3mm]{standalone}
\usetikzlibrary{angles, arrows.meta,
                backgrounds, bending,
                quotes}
\pgfset{arrow keys/fill opacity/.code=
    \pgfarrowsaddtooptions{\pgfsetfillopacity{#1}}  % <--- new arrow option!
        }
\tikzset{
          arr/.style = {-{#1[fill opacity=1]}, thin},
        arr/.default = Stealth,
my angle/.style args = {#1/#2/#3/#4}{draw=#1, arr=#2,
                        fill=#1!30, fill opacity=#3,
                        angle radius = #4,
                        angle eccentricity=1.3},
my angle/.default    = {blue/Triangle/1/5mm},
        }
\begin{document}
    \begin{tikzpicture}[line width=0.8pt]
\pgfmathsetmacro{\r}{4}
\pgfmathsetmacro{\R}{\r+0.7}
\pgfmathsetmacro{\A}{80}
\pgfmathsetmacro{\B}{150}

% coordonnés
\draw[arr] (-\R,0) -- (\R,0)   coordinate[label=below  left:$x$] (X);
\draw[arr] (0,-\R) -- (0,\R)   coordinate[label=below right:$y$] (Y);
% cercle
\draw (0,0) coordinate (O) circle(\r);
%% Valeurs d'angles
\coordinate (A) at (\A:\r);
\coordinate (B) at (\B:\r);

%% Représentation des angles
\scoped[on background layer]
{
\pic[my angle,  "$\beta$",
     pic text options={xshift=-11pt}]   {angle=X--O--B};
\pic[my angle=red/Stealth/0.6/7mm,
                "$\alpha$"]             {angle=X--O--A};
}
\draw[line join=bevel] (A) -- (O) -- (B);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .