6

I'm trying to create a figure using Tikz. A part of the figure looks like this.

\documentclass[11pt, a4paper]{article}
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
%Outer lining of the tube.
\draw {[rounded corners=0.2cm] (6.3,1.0) -- (6.3,-1.0) -- (8.3,-1.0) -- (8.3,-4.0)};
\draw {[rounded corners=0.2cm] (6.0,1.0) -- (6.0,-1.3) -- (8.0,-1.3) -- (8.0,-4.0)};
\draw {[rounded corners=0.2cm] (9.3,-4.0) -- (9.3,-1.0) -- (11.6,-1.0) -- (11.6,0.0)};
\draw {[rounded corners=0.2cm] (9.6,-4.0) -- (9.6,-1.3) -- (11.9,-1.3) -- (11.9,0.0)};

%Round bend which also needs to be filled with a color.
\def\arca {(8.3,-4.0) arc (180:0:0.5 and -0.5)}
\def\arcb {(8.0,-4.0) arc (180:0:0.8 and -0.8)}
\path [draw=black] \arca;
\path [draw=black] \arcb;

%Lines that are indicating a level. Space under these lines needs to be colored.
\draw (8.0,-2.5) -- (8.3,-2.5);
\draw [dashed] (8.3,-2.5) -- (10.3,-2.5);
\draw (9.3,-3.5) -- (9.6,-3.5);
\draw [dashed] (9.6,-3.5) -- (10.3,-3.5);
\draw [thick, <->] (10.2,-2.5) -- (10.2,-3.5);
\draw (10.6,-3.0) node {\begin{small}$\Delta P$\end{small}};
\end{tikzpicture}
\end{figure}
\end{document}

This is creating the following figure: Tube without coloring

Now I want to fill the space under the lines that are indicating the level (the lines marked by the $\Delta P$). So in the end it should look something like this (only nicely filled, not as sloppy as in the this picture). Tube with Coloring under the level lines

I have read a lot of examples of other (similar) questions, but I am still not able of figuring out how to do this. Does someone have a simple solution to this (I am not very well trained with Latex or Tikz as you can probably see).

Thanks in advance!

  • A warm welcome to TeX.SE! – A Feldman Apr 24 '16 at 16:27
  • Just recreate the path for the filled area and use either \path[fill=black] or \fill[black]. – John Kormylo Apr 24 '16 at 16:28
  • Thanks for the welcome and the replay. How do I recreate a path for the area that needs to be filled such that I can fill it? I can draw lines for the filled area in a way like I have done so far, but that leaves with the same problem. How do I integrate the \path[black] such that Latex knows what to fill? – Gregory Apr 24 '16 at 16:42
5

As mentioned in the comments you can create a path from the arcs you already defined for filling. I just slightly redefined your arca :

\documentclass[11pt, a4paper]{article}
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
%Outer lining of the tube.
\draw {[rounded corners=0.2cm] (6.3,1.0) -- (6.3,-1.0) -- (8.3,-1.0) -- (8.3,-4.0)};
\draw {[rounded corners=0.2cm] (6.0,1.0) -- (6.0,-1.3) -- (8.0,-1.3) -- (8.0,-4.0)};
\draw {[rounded corners=0.2cm] (9.3,-4.0) -- (9.3,-1.0) -- (11.6,-1.0) -- (11.6,0.0)};
\draw {[rounded corners=0.2cm] (9.6,-4.0) -- (9.6,-1.3) -- (11.9,-1.3) -- (11.9,0.0)};

%Round bend which also needs to be filled with a color.
\def\arca {(9.3,-4.0) arc (180:0:-0.5 and -0.5)}
\def\arcb {(8.0,-4.0) arc (180:0:0.8 and -0.8)}
% constructing, drawing and filling path
\path[draw,fill=red] (8,-2.5) -- (8,-4) -- \arcb -- (9.6,-4) -- (9.6,-3.5) -- (9.3,-3.5) -- (9.3,-4)  -- \arca  -- (8.3,-4) -- (8.3,-2.5) -- cycle;

%Lines that are indicating a level. Space under these lines needs to be colored.
\draw [dashed] (8.3,-2.5) -- (10.3,-2.5);
\draw [dashed] (9.6,-3.5) -- (10.3,-3.5);
\draw [thick, <->] (10.2,-2.5) -- (10.2,-3.5);
\draw (10.6,-3.0) node {\begin{small}$\Delta P$\end{small}};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

  • Seriously, it is just this simple. Thanks for answering my question! It worked. I guess the 'cycle' part makes a closed loop? – Gregory Apr 24 '16 at 17:15
  • Your completely right. It closes the path. – JMP Apr 24 '16 at 17:16
  • 2
    Just for completeness: Instead of \path[draw,fill=red] you could also just say \filldraw[fill=red] – JMP Apr 24 '16 at 17:35
3

An alternative with double lines. double distance defines pipe width and double=... filling color which by default is white. This means that over a non white background the pipe is not transparent.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[pipe/.style={draw, double, double distance=3mm, rounded corners=2mm},
    pipefull/.style={pipe, double=red}]

%Outer lining of the tube.
\draw[pipe] (6,1) |- ++(2,-2) -- ++(0,-3) coordinate (aux1) arc(-180:-0:0.6) coordinate (aux2) |-++(2,3)--++(0,2);

\draw[pipefull] ([yshift=2cm]aux1) coordinate(top) -- (aux1) arc(-180:-0:0.6) -- ([yshift=1cm]aux2) coordinate(bottom) ;

\draw[dashed] (top)--++(0:20mm) coordinate (aux3);
\draw[dashed] (bottom) -- (aux3|-bottom) coordinate (aux4);
\draw[<->,thick] ([xshift=-2mm]aux3)-- node[right, font=\small]{$\Delta P$} ([xshift=-2mm]aux4);

\end{tikzpicture}
\end{document}

enter image description here

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.