TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My question was inspired by Rotate fading in tikz where the inquiror is drawing laser beams that shall look somewhat blurred not as lines but as boxes with a fading. The problem with this approach is that the fading has to be turned according to the orientation via quite unhandy canvas transformations. Above that curved lines are not possible this way.

That made me think if there is way to draw fading or blurred lines in a more convenient manner, maybe by applying some kind of very closely repeated decoration template to a path? Any ideas?

share|improve this question
I can imagine that in a curvy line those small steps would cause a lot of aliasing problems. – percusse Nov 2 '12 at 21:21
up vote 16 down vote accepted

Here is a proposition using recursive preaction (each of the ten preactions draws the path with draw opacity=.1 and line width increased by .2pt):

enter image description here

  laser beam action/.style={
    line width=\pgflinewidth+.2pt,draw opacity=.1,draw=#1,
  laser beam recurs/.code 2 args={%
    {\tikzset{preaction={laser beam action=#2}}}%
    {\tikzset{preaction={laser beam action=#2,laser beam recurs={\level}{#2}}}}
  laser beam/.style={preaction={laser beam recurs={10}{#1}},draw opacity=1,draw=#1},
  \fill[lime] circle(1cm);
  \path[preaction={fill=black},laser beam=yellow,] (1,2) circle(1cm and 5mm);
  \path[laser beam=red] (0,0) -- (2,2);
  \path[rounded corners=5mm,laser beam=blue] (0,0) -- (3,0) -- (0,-2);
  \path[line width=4pt,laser beam=orange] (0,0) -- (-1,2);
share|improve this answer
Very nice solution! – Benedikt Bauer Nov 3 '12 at 11:44

Since the proposed solution seemed to be too complicated if only straight lines should be drawn, I gave it another shot and came up with the following solution that involves the shadings library and canvas transformation:


\usetikzlibrary{shadings} % libraries for this TikZ picture
    \draw (0,0) rectangle (2,2);
    \begin{scope}[transform canvas={rotate=30}] % rotate by 30 degree
        \shade[shading=axis,bottom color=white,top color=white,middle color=black,shading angle=0] (1,0) rectangle (2,0.2);


Line with fading, rotated by 30 degree

This answer is inspired by this answer of user rgallego.

share|improve this answer
But this solution does only work as long as lines (which you "simulate" by rectangles) are straight, right? What about curved lines? – Benedikt Bauer Mar 10 '14 at 14:09
@BenediktBauer You are absolutely right. I updated the answer accordingly. – Peter Pablo Mar 10 '14 at 14:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.