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);
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

  • 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 '16 at 13:08
  • @emab double distance=XX – flav Jun 6 '16 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

  • You may use \fill instead of \draw to remove small black lines... – Paul Gaborit Jun 6 '16 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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