6

I wanted a fading line with the same color at both the ends and a second color in the middle. Here is the crude MWE I came up with:

\documentclass{article}
\usepackage{tikz}                                                                       
\begin{document}
  \begin{tikzpicture}[baseline]
    \path[left color=white,right color=black]
    (0,0) rectangle (.5\textwidth,.5pt);%
    \path[left color=black,right color=white]
    (.5\textwidth,0) rectangle (\textwidth,.5pt); 
  \end{tikzpicture}
\end{document}

This leaves a tiny tiny gap in the center. (Or is it just an optical illusion I get because I know I have used two path commands?)

Is there a better way of doing it? May be, with only one path/ fill/ rectangle command?

deshmukh
  • 2,435
  • 1
  • 26
  • 46

1 Answers1

5

You may use the middle color key (after right color and left color keys):

\documentclass{article}
\usepackage{tikz}                                                                       
\begin{document}
\noindent\begin{tikzpicture}[baseline]
    \path[left color=white,right color=white,middle color=black]
    (0,0) rectangle (\textwidth,.5pt);%
  \end{tikzpicture}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283