Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jan 14 '13 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. –  Lionel MANSUY Jan 14 '13 at 12:25

1 Answer 1

up vote 4 down vote accepted

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

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
\def\myuppercolor{yellow}
\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);
\end{tikzpicture}

\end{document}

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

share|improve this answer
    
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 Jan 14 '13 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 Jan 14 '13 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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