# how to highlight (with glow) any path using Tikz?

I need to be able to do this kind of highlighting (or glow) on different figures like vectors, lines, circles, arcs, but I have no idea how to do it, this is a code example

\documentclass[,varwidth,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{pgf,tikz,tikz-3dplot}
%
\begin{document}
%
\begin{tikzpicture}[ >=latex]
\draw[->] (-4,0)--(5,0) node[at end,above]{$x$};
\draw[->] (0,-1,0)--(0,5,0) node[at end,right]{$y$};
\draw[->] (0,0) coordinate(O) -- ({5*cos(30)},{5*sin(30)}) coordinate (XP)  node[pos=1.1]{$x'$};
\draw[->] (O) -- ({-5*sin(30)},{5*cos(30)}) coordinate (YP) node[pos=1.1]{$y'$};
\draw[->, red] (O) -- ({4*cos(50)}, {4*sin(50)}) coordinate(R);
\draw[blue] (R)|-coordinate (Q) (O);
\draw[green] (O) -- ({4*cos(50)*cos(30)*cos(30)}, {4*cos(50)*cos(30)*sin(30)})-- (Q);
\draw[<->, Orchid] (1.25,0) arc (0:30:1.25cm) node[midway, right ]{$\theta_{11}$};
\draw[<->, Firebrick2] (30:1.25) arc (30:50:1.25cm) node[midway, right ]{$\theta_{12}$};
\draw[yellow] (Q)--++({ 4*sin(50)*sin(30)*cos(30) }, { 4*sin(50)*sin(30)*sin(30) } )-- (R);
\end{tikzpicture}
%
\end{document}


this is an example of "this glow"

Thanks for the help!!

• @mabartibin: It would be wonderful, if blur shadow had a color option, so it could be used for things like this. Nov 4 '20 at 22:33
• yes, It would be!!! Nov 5 '20 at 1:01

I made a glow style, that simply draws the line several times with increasing thickness and and low opacity. The glow can be a different color from the line. If the line has an arrow it look strange, but you can simply draw it first with glow, and the again with the arrow.

\documentclass[,varwidth,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{pgf,tikz,tikz-3dplot}
\tikzset{%
glow/.style={%
preaction={#1, draw, line join=round, line width=0.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=1.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=1.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=2.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=2.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=3.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=3.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=4.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=4.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=5.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=5.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=6.0pt, opacity=0.04,
}}}}}}}}}}}}}}
\begin{document}
\begin{tikzpicture}[ >=latex]
\draw[->] (-4,0)--(5,0) node[at end,above]{$x$};
\draw[->] (0,-1,0)--(0,5,0) node[at end,right]{$y$};
\draw[->] (0,0) coordinate(O) -- ({5*cos(30)},{5*sin(30)}) coordinate (XP)  node[pos=1.1]{$x'$};
\draw[->] (O) -- ({-5*sin(30)},{5*cos(30)}) coordinate (YP) node[pos=1.1]{$y'$};
\draw[->, red, glow=red] (O) -- ({4*cos(50)}, {4*sin(50)}) coordinate(R);
\draw[blue, glow=orange] (R)|-coordinate (Q) (O);
\draw[glow=cyan] (O) -- ({4*cos(50)*cos(30)*cos(30)}, {4*cos(50)*cos(30)*sin(30)})-- (Q) -- cycle;
\draw[<->, Orchid] (1.25,0) arc (0:30:1.25cm) node[midway, right ]{$\theta_{11}$};
\draw[<->, Firebrick2] (30:1.25) arc (30:50:1.25cm) node[midway, right ]{$\theta_{12}$};
\draw[glow=yellow] (Q)--++({ 4*sin(50)*sin(30)*cos(30) }, { 4*sin(50)*sin(30)*sin(30) } )-- (R);
\end{tikzpicture}
\end{document}


Careful consideration needs to be taken on the order of the lines and glows, so that they are not painted on top of each other. Like in this zoom:

The easiest way to avoid problems are to draw all glows first(or on a background layer) and then the normal lines.

Edit:

This glow has rounded ends, and do not overwrite the original lines. Using the solution from Pass options to the scope that is internally created by preaction:

\documentclass[tikz, border=0.1 cm]{standalone}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\makeatletter
\pgfkeys{%
/tikz/on layer/.code={
\pgfonlayer{#1}\begingroup
\aftergroup\endpgfonlayer
\aftergroup\endgroup
},
/tikz/node on layer/.code={
\pgfonlayer{#1}\begingroup
\expandafter\def\expandafter\tikz@node@finish\expandafter{\expandafter\endgroup\expandafter\endpgfonlayer\tikz@node@finish}%
},
}
\tikzset{%
glow/.style={%
preaction={#1, draw, line cap=round, line join=round, line width=0.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=1.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=1.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=2.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=2.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=3.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=3.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=4.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=4.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=5.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=5.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=6.0pt, opacity=0.04, on layer=back,
}}}}}}}}}}}}}}
\begin{document}
\begin{tikzpicture}
\draw[glow=red] (0,0.5) -- (1,0.5);
\draw[glow=red] (0.5,0) -- (0.5,1);
\end{tikzpicture}
\end{document}


Zoom:

Random glowing lines:

• yes hpekristiansen, after a few tests, your code works better than I thought at first!! thanks again! Nov 5 '20 at 16:23

You can just draw some thick line in the background. This can be done either with the backgrounds library, by a preaction, just drawing the thick lines earlier, or combinations of these. If you set the opacity to nontrivial values, it can make sense to use a transparency group.

\documentclass[,varwidth,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{tikz}
%
\begin{document}
%
\begin{tikzpicture}[ >=latex,glow/.style={%
preaction={draw,line cap=round,line join=round,
opacity=0.3,line width=4pt,#1}},glow/.default=yellow,
transparency group]
\draw[->] (-4,0)--(5,0) node[at end,above]{$x$};
\draw[->] (0,-1,0)--(0,5,0) node[at end,right]{$y$};
\draw[->] (0,0) coordinate(O) -- ({5*cos(30)},{5*sin(30)}) coordinate (XP)  node[pos=1.1]{$x'$};
\draw[->] (O) -- ({-5*sin(30)},{5*cos(30)}) coordinate (YP) node[pos=1.1]{$y'$};
\draw[->, red] (O) -- ({4*cos(50)}, {4*sin(50)}) coordinate(R);
\draw[glow] (R) -- (R|-O)coordinate (Q);
\draw[glow={cyan!50}] (Q) -- (O) --
({4*cos(50)*cos(30)*cos(30)},{4*cos(50)*cos(30)*sin(30)}) coordinate (A) -- cycle;
\draw[blue] (R)|- (O);
\draw[green] (O) -- (A)-- (Q);
\draw[<->, Orchid] (1.25,0) arc (0:30:1.25cm) node[midway, right ]{$\theta_{11}$};
\draw[<->, Firebrick2] (30:1.25) arc (30:50:1.25cm) node[midway, right ]{$\theta_{12}$};
\draw[orange,glow] (Q)--++({ 4*sin(50)*sin(30)*cos(30) }, { 4*sin(50)*sin(30)*sin(30) } )
coordinate (B)-- (R);
\end{tikzpicture}
%
\end{document}


• Almost, but is not the same effect, you can observe the detail of the transparency from the center to the edge of the highlight, Thank you for your help! Nov 4 '20 at 18:38
• this was my first step, tex.stackexchange.com/questions/73220/… Nov 4 '20 at 18:40
• @AlejandroMunozOssa Then you may be looking for this answer.
– user227987
Nov 4 '20 at 19:39
• I would also suggest the laser solution. An other way is to use a biquadratic patch from PGFPlots: tex.stackexchange.com/a/173310/8650 Nov 4 '20 at 20:39
• Nice solution -one thing: transparency group does not work like this. It needs to be a scope with common transparency. -it will not prevent a darkening of the glow when overlapping. Nov 5 '20 at 4:36