How would I draw the following figure in latex:

enter image description here

I can draw this by drawing two circles and then a line connecting them, and insert the text by using \node in the tikz package but this seems a very long winded way of doing this, is there another approach I should be adopting. In addition, I wish to add another diagram that is conically shaped i.e. identical to this diagram but in the shape of an inverted cone. The diagram is intended to show the amount of fluid in the given shape where the denser fluid (black) is located beneath the lighter fluid.

Thanks in advance for your suggestions.

  • What you describe is four lines of code and that's currently labeled as a long winded way. I don't know if anything shorter exists.
    – percusse
    Commented Jan 14, 2013 at 12:06
  • Maybe you could define a new node type using \pgfdeclareshape and a few keys to fill the cylinder to the desired height. Commented Jan 14, 2013 at 12:25

1 Answer 1


I'm not certain if i met with the quintessence of your question, nevertheless here's how i would do that.


\begin{tikzpicture}[mycyl/.style={cylinder, shape border rotate=90, draw, minimum width=1cm, aspect=0.25, %
anchor=south, text width=1cm, text height=.1cm}, %
    \node [mycyl , fill=blue, minimum height=1.6cm] (bl) at (0,0) {};
    \node [mycyl , minimum height=.3cm, fill = \myuppercolor] (yell) at (0,1) { };
    % dashed "mixing lines"
    % note they are calculated manually (according to the aspect key of the cylinder shape)
    \foreach \y in {.6, .7, .8}{
        \draw[dashed, \myuppercolor] (.619,\y+.3) arc[x radius=.619cm, y radius=.154cm, start angle=0, end angle=-180];}
    %, descriptions 
    \node[above of=yell]{$A_0$};
    \node[right of=yell, xshift=.2cm]{$h$};
    \draw[<->, ] ([xshift = 1cm]yell.top) -- ([xshift = 1cm]yell.bottom);
        \draw[->,dashed ] ([xshift = 1cm]yell.bottom) -- ([xshift = 1cm]bl.center);


Please note: i calculated the keys for the arc command manually. It's quite easy since aspect gives you the fraction of y and x height of the ellipsis. For me that`s the most economic way.

enter image description here

  • thats great. You wrote (yell) to make the dashed line yellow, how do I change this color e.g. to be black? I can change the color of the yellow in the upper region by fill = blue!70 but I cannot seem to change the color of the lines!
    – KatyB
    Commented Jan 14, 2013 at 14:19
  • I added some lines to make the three parts of the drawing more emphasized. Those "mixing lines" are defined by a simple \draw command with the color command right beside. Plus i added a macros which stores the desired color. Just alter \def\myuppercolor{yellow} to \def\myuppercolor{<whatever>}
    – bloodworks
    Commented Jan 14, 2013 at 14:25

You must log in to answer this question.

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