有什么建议关于如何在圆柱体中放置一些线(如刻度)来指示圆柱体的高度?
它看起来应该是这样的:
这是我的 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}
答案1
干得好:
\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}
这是另一个版本,它将平均划分高度
\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}
如果你只想要以下几行:
\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}
只是为了回应评论:
\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}
答案2
您可以将以下内容添加到您的\tikzpicture
:
\draw[|<->|]([xshift=6mm,yshift=-2mm]1.north)--node[right]{$s$}([xshift=6mm]1.south) ;
给予: