[Tex/LaTex] Tikz: drawing border or line with shade

tikz-pgf

I want to draw a line with a shade, not a big rectangle.

As per the documentation,

Shading is caused by the shade option (there are \shade and \shadedraw abbreviations).

Shouldn't therefore something like this work?

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [shade, left color=red, right color=blue] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}

But I cannot get it to be shaded. It always shows up like this:line


In actuality, what I want to draw is a rectangle where the end of the borders are shaded this way:

rectangle with shaded borders

There is probably a simple way to do this, but I only see forms of doing filled shade, not border shades or single lines…

Best Answer

You can use path fading from fadings library.

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{fadings}
\begin{document}
  \tikz
    \draw[blue,thick,path fading=east] (0,0) rectangle (4,1);
\end{document}

enter image description here