# drawing two identical tubes to illustrate a math problem

I am modifying the codes by percusse in this website for my math problem. Could you help to add the marking for the tube on the right?

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=.54]
(-1,-2)--(-1,-5) arc (180:360:1)  -- (1,-2) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);
\draw[red!90!black!70] (0,-2) ellipse (1 and .3);

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
{
\draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

\foreach \z in {0.2,0.4,0.6,0.8}
\draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
};

(3,-2.7)--(3,-5) arc (180:360:1)  -- (5,-2.7) arc (0:180:1 and 0.3);
\draw (4,0) ellipse (1 and .3);
\draw (3,0)--(3,-5) arc (180:360:1) --(5,-5) -- (5,0);
\draw[red!90!black!70] (4,-2.7) ellipse (1 and .3);

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
{
\draw (3.8,\y) to[bend right=10](4.2,\y) node[right,yslant=0.15](\x){};

\foreach \z in {0.2,0.4,0.6,0.8}
\draw ($(-0.1,\z) + (0,\y)$)to[bend right=15]($(0.1,\z)+(0,\y)$);
};
\end{tikzpicture}

\end{document}

• Commented Oct 21, 2015 at 6:39

You can define a pic and then reuse it with custom parameters at custom position.

Note: The code of the tube is taken from this answer of @percusse.

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

\tikzset{
tube/.pic={
\pgfmathsetmacro\level{#1-5.7}
(-1,\level)--(-1,-5) arc (180:360:1) -- (1,\level) arc (0:180:1 and 0.3);
\draw[.!90!black!70] (0,\level) ellipse (1 and .3);
\begin{scope}[black]
\draw (0,0) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);
\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}{
\draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){\x};
\foreach \z in {0.2,0.4,0.6,0.8}
\draw[yshift=\y cm] (-0.1,\z)to[bend right=5](0.1,\z);
};
\end{scope}
}
}

\begin{document}
\begin{tikzpicture}
\pic[red]{tube=2};
\path (3,0) pic[blue]{tube=3.4} ++(3,0) pic[green]{tube=2.8};
\end{tikzpicture}
\end{document}


• How can we change the numbere 1, 2, 3, 4 to 100, 200, 300, 400?
– Epa
Commented Oct 22, 2015 at 13:29
• @Thumbolt In place of node[right,yslant=0.15](\x){\x} you can put node[right,yslant=0.15]{\x00} (the node name (\x) is useless here).
– Kpym
Commented Oct 22, 2015 at 16:29

You can use shift here. Draw the same tube once again with xshift=4cm, say, and adjust the fill height and the red ellipse.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=.54]
(-1,-2)--(-1,-5) arc (180:360:1)  -- (1,-2) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);
\draw[red!90!black!70] (0,-2) ellipse (1 and .3);   %% put this before
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);    %% put this line here

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
{
\draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

\foreach \z in {0.2,0.4,0.6,0.8}
\draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
};

\begin{scope}[xshift=4cm]
(-1,-2.7)--(-1,-5) arc (180:360:1)  -- (1,-2.7) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);

\draw[red!90!black!70] (0,-2.7) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);   %% put this line here

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
{
\draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

\foreach \z in {0.2,0.4,0.6,0.8}
\draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
};
\end{scope}

%    (3,-2.7)--(3,-5) arc (180:360:1)  -- (5,-2.7) arc (0:180:1 and 0.3);
%\draw (4,0) ellipse (1 and .3);
%\draw (3,0)--(3,-5) arc (180:360:1) --(5,-5) -- (5,0);
%\draw[red!90!black!70] (4,-2.7) ellipse (1 and .3);
%
%
%\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
%    {
%    \draw (3.8,\y) to[bend right=10](4.2,\y) node[right,yslant=0.15](\x){};
%
%    \foreach \z in {0.2,0.4,0.6,0.8}
%       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=15]($(0.1,\z)+(0,\y)$);
%    };
\end{tikzpicture}

\end{document}