4

Any advice how to place some lines (like ticks) in the cylinder indicating the cylinder height?

It should look like this: enter image description here

Here my MWE:

\documentclass[english]{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{babel}

\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds,calc}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes.geometric}

\tikzset{
    node_standard/.style = {
        ->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,thick,
        main node/.style={
            circle,
            fill=gray!25,
            draw,
            font=\sffamily\footnotesize
        },
        cylinder node/.style={
            cylinder,
            draw=black,
            thick,
            aspect=0.9,
            minimum width=0.8cm,
            shape border rotate=90,
            anchor=bottom,
            font=\sffamily\footnotesize,
            cylinder uses custom fill,
            cylinder body fill=gray!15,
            cylinder end fill=gray!25,
            text height=0.08cm
        },
        height1/.style={
            minimum height=5mm,
        },
        height2/.style={
            minimum height=10mm,
        },
        height3/.style={
            minimum height=15mm,
        },
        height4/.style={
            minimum height=20mm,
        },
    }
}

\begin{document}
    \begin{tikzpicture}[node_standard]

        \node[cylinder node,height4]    (1)     {$a$};

    \end{tikzpicture}
\end{document}
Frank
  • 501

2 Answers2

4

Here you go:

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds,calc}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}

\tikzset{
    node_standard/.style = {
        ->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,thick,
        main node/.style={
            circle,
            fill=gray!25,
            draw,
            font=\sffamily\footnotesize
        },
        cylinder node/.style={
            name=cyl,   %% named here
            shape=cylinder,   %% slightly changed
            draw=black,
            thick,
            aspect=0.9,
            minimum width=0.8cm,
            shape border rotate=90,
            anchor=bottom,
            font=\sffamily\footnotesize,
            cylinder uses custom fill,
            cylinder body fill=gray!15,
            cylinder end fill=gray!25,
            text height=0.08cm
        },
        height4/.style={
            minimum height=28mm,   %% height increased to accomodate scales
        },
    }
}

\begin{document}
    \begin{tikzpicture}[node_standard]
        \xdef \maxht{20}
        \node[cylinder node,height4]       {$a$};
        \foreach \y in {1,...,20}{
          \draw[-,very thin] ($(cyl.after bottom) + (0,\y mm)$) -- +(1mm,0);
          }
        \foreach \y in {0,5,...,\maxht}{
          \draw[-,thin] ($(cyl.after bottom) + (0,\y mm)$) -- +(1.4mm,0)node[scale=0.25,anchor=west,inner sep=0pt,xshift=-3pt]{\SI{\y}{\milli\liter}};
          }
    \end{tikzpicture}
\end{document}

enter image description here

here is another version that will divide the height equally

\documentclass[border=3mm]{standalone}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds,calc}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}

\tikzset{
    node_standard/.style = {
        ->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,thick,
        main node/.style={
            circle,
            fill=gray!25,
            draw,
            font=\sffamily\footnotesize
        },
        cylinder node/.style={
            name=cyl,   %% named here
            shape=cylinder,   %% slightly changed
            draw=black,
            thick,
            aspect=0.9,
            minimum width=0.8cm,
            shape border rotate=90,
            anchor=bottom,
            font=\sffamily\footnotesize,
            cylinder uses custom fill,
            cylinder body fill=gray!15,
            cylinder end fill=gray!25,
            text height=0.08cm
        },
        height4/.style={
            minimum height=20mm,   
                   },
    }
}

\begin{document}
    \begin{tikzpicture}[node_standard]
        \node[cylinder node,height4]       {$a$};
        \foreach \y in {0,0.05,...,1}{
          \draw[-,very thin] ($(cyl.after bottom) !\y! (cyl.before top)$) -- +(1mm,0);
          }
        \foreach \y in {0,0.25,...,1}{
          \draw[-,thin] ($(cyl.after bottom) !\y! (cyl.before top)$) -- +(1.4mm,0)node[scale=0.25,anchor=west,inner sep=0pt,xshift=-3pt]{\SI{\y}{\milli\liter}};
          }
    \end{tikzpicture}

\end{document}

enter image description here

If you want just the lines:

\begin{tikzpicture}[node_standard]
\xdef \maxht{20}
\node[cylinder node,height4]       {$a$};
\foreach \y in {0,.1,...,1}{
  \draw[-,thin] ($(cyl.after bottom) !\y! (cyl.before top)$) -- +(2mm,0);
  }
\end{tikzpicture}

enter image description here

Just to address the comments:

\documentclass[border=3mm]{standalone}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds,calc}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}

\tikzset{
    node_standard/.style = {
        ->,>=stealth',shorten >=1pt,node distance=2.5cm,auto,thick,
        main node/.style={
            circle,
            fill=gray!25,
            draw,
            font=\sffamily\footnotesize
        },
        cylinder node/.style={
            name=cyl,   %% named here
            shape=cylinder,   %% slightly changed
            draw=black,
            thick,
            aspect=0.9,
            minimum width=0.8cm,
            shape border rotate=90,
            anchor=bottom,
            font=\sffamily\footnotesize,
            cylinder uses custom fill,
            cylinder body fill=gray!15,
            cylinder end fill=gray!25,
            text height=0.08cm,
        },
        height4/.style={
            minimum height=20mm,
                   },
    },
    pics/.cd,
    ticks/.style args={#1#2#3}{
    code={
    \node[cylinder node,#1]       {$#3$};
     \foreach \y in {0,.#2,...,1}{
       \draw[-,thin] ($(cyl.after bottom) !\y! (cyl.before top)$) -- +(2mm,0);
            }
  }
},
}

\begin{document}
    \begin{tikzpicture}[node_standard]
        \path pic {ticks={height4}{5}{a}};
    \end{tikzpicture}

\end{document}
  • Thanks! But isn't it possible to include it in the "cylinder node/.style" tikzset? ;-) – Frank Sep 04 '14 at 11:06
  • @Frank As such, no!. But you can define a pic if we know your needs exactly. –  Sep 04 '14 at 11:10
  • Your second version would fit perfectly. I just need the ticks to indicate the height. An example: if the cylinder should be 2 units i define it by writing "height2" or "height3" for 3 units. Between those units should be ticks: a "height3 cylinder should have 2 ticks, a "height4" should have 3 ticks .. and so on. Maybe you know a way to include it into the "height1/.style", "height2/.style" ... style? – Frank Sep 04 '14 at 11:21
  • so it isn't about filling the cylinder, but indicating the height, whether its 2, 3, 4 ... ;) (its every 5 mm, as you see in the definition of those heights – Frank Sep 04 '14 at 11:24
  • @Frank See the update at the end with pic. –  Sep 04 '14 at 12:18
2

You can add the following to to your \tikzpicture:

\draw[|<->|]([xshift=6mm,yshift=-2mm]1.north)--node[right]{$s$}([xshift=6mm]1.south) ;

to give:

enter image description here