7

I am drawing two lines and I need to fill the space between them with a green color. How can I do that in tikz?

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}
            \draw (3.1,4.2) -- (2.45,3.8)  (3.1,4.1) -- (2.45,3.7);
    \end{tikzpicture}

\end{document}

I know one way is to draw a green thick line between these two. But I don't want to do that, as it is difficult to align these lines:

            \draw (3.1,4.2) -- (2.45,3.8)  (3.1,4.12) -- (2.45,3.72);
            \draw[line width=0.55mm, green] (3.1,4.16) -- (2.45,3.76);

2 Answers 2

7

using double :

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
  \draw[double=green] (3.1,4.2) -- (2.45,3.8);
\end{tikzpicture}
\begin{tikzpicture}
  \draw[double=green, double distance=.1cm] (3.1,4.2) -- (2.45,3.8);
\end{tikzpicture}
\begin{tikzpicture}
  \draw[double=green, double distance=.2cm] (3.1,4.2) -- (2.45,3.8);
\end{tikzpicture}
\end{document}

enter image description here

2
  • Thanks, How can I adjust the thickness of each line? (I am interested in adjusting thickness of the black ones and green one).
    – orezvani
    Jun 6, 2016 at 13:08
  • @emab double distance=XX
    – flav
    Jun 6, 2016 at 16:24
1

It is not a perfect solution. The problem are line ends (I made them round, but it is a matter of taste):

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}
        \draw [fill=green, line width=0.mm](3.1,4.2) -- (2.45,3.8) -- (2.45,3.7) -- (3.1,4.1) --cycle;
            \draw[line cap=round] (3.1,4.2) -- (2.45,3.8)  (3.1,4.1) -- (2.45,3.7);

    \end{tikzpicture}

\end{document}

enter image description here

1
  • You may use \fill instead of \draw to remove small black lines... Jun 6, 2016 at 9:37

You must log in to answer this question.

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