![如何使用 tikz 绘制传感器和执行器图表](https://linux22.com/image/460080/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20tikz%20%E7%BB%98%E5%88%B6%E4%BC%A0%E6%84%9F%E5%99%A8%E5%92%8C%E6%89%A7%E8%A1%8C%E5%99%A8%E5%9B%BE%E8%A1%A8.png)
代码如下。
\documentclass[12pt,letterpaper]{article}
\usepackage[left=20mm,top=30mm,bottom=30mm,right=20mm]{geometry}
\usepackage{tikz} % for drawing pictures
\usetikzlibrary{arrows.meta,
chains,
positioning,
quotes,
shapes.geometric, arrows}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto,
node distance = 15mm and 19mm,
start chain = going right,
arr/.style = {->},>=Latex,
block/.style = {draw, minimum height=3em, minimum
width=4em,align=center,fill=blue!20},
sum/.style = {circle, draw, node contents={}},
]
\begin{scope}[nodes={on chain, join=by arr}]
\coordinate (in);
\node (n4) [block] {$K_m = 2 \times 10^{-1}$ \\ $N mV^{-1}$};
\node (n5) [block] {$K_s = 5 \times 10^{-2}$ \\ $rad \hspace{1mm} N^{-1} m^{-1}$};
\coordinate (out);
\path (n4) to [below, pos=0.5,"$T$"] (n5) (out) ;
\path (n4) to [below, pos=0.5,"$V$"] (in) ;
\path (n5) to [below, pos=0.5,"$\theta$"] (out) ;
\end{tikzpicture}
\end{center}
\end{document}
下面的图片是我从上面的代码中得到的。
以下是我想要实现的。
答案1
抱歉,我之前没有空出来……
可能的解决方案是:
\documentclass[12pt,letterpaper]{article}
\usepackage[hmargin=20mm,vmargin=30mm]{geometry}
\usepackage{siunitx}
\usepackage{tikz} % for drawing pictures
\usetikzlibrary{arrows.meta,
decorations.markings,
positioning,
quotes,
shapes.geometric}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto,
node distance = 1mm and 19mm,
block/.style = {draw, fill=blue!20,
minimum height=3em, minimum width=4em, align=center,
label=below:#1
},
sum/.style = {circle, draw, node contents={}},
%
arr/.style = {-{Stealth[scale=1.6]}},
->-/.style = {decoration = {markings,mark=at position 0.5
with {\arrow[scale=1.6]{Stealth}}},
postaction={decorate}},
every edge quotes/.append style = {anchor=center, align=center}
]
\coordinate (in);
\node (n4) [block=Motor, right=of in] {$K_m=2\times 10^{-1}$ \\ \unit{N mV^{-1}}};
\node (n5) [block=Spring, right=of n4] {$K_s=5\times 10^{-2}$ \\ \unit{\radian\per\newton\per\metre}};
\coordinate[right=of n5] (out);
\draw (in) edge [->-,"$V$\\ Volts"] (n4)
(n4) edge [->-,"$T$\\ \unit{\newton\meter\second}"] (n5)
(n5) edge [arr, "$\theta$\\ rad"] (out);
\end{tikzpicture}
\end{center}
\end{document}
附录: 节点“阻塞”在链中的情况。
\usepackage[hmargin=20mm,vmargin=30mm]{geometry}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains, % added
decorations.markings,
positioning,
quotes,
shapes.geometric}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto,
node distance = 1mm and 19mm,
start chain = going right,
CB/.style = {draw, fill=blue!20, % ChainBlock
minimum height=3em, minimum width=4em, align=center,
on chain, % added
label=below:#1
},
sum/.style = {circle, draw, node contents={}},
%
arr/.style = {-{Stealth[scale=1.6]}},
->-/.style = {decoration = {markings,mark=at position 0.5
with {\arrow[scale=1.6]{Stealth}}},
postaction={decorate}},
every edge quotes/.append style = {anchor=center, align=center}
]
\coordinate[on chain] (in); % added option "on chain"
\node (n4) [CB=Motor] {$K_m=2\times 10^{-1}$ \\ \unit{N mV^{-1}}};
\node (n5) [CB=Spring]{$K_s=5\times 10^{-2}$ \\ \unit{\radian\per\newton\per\metre}};
\coordinate[on chain] (out); % added option "on chain"
\draw (in) edge [->-,"$V$\\ Volts"] (n4)
(n4) edge [->-,"$T$\\ \unit{\newton\meter\second}"] (n5)
(n5) edge [arr, "$\theta$\\ rad"] (out);
\end{tikzpicture}
\end{center}
\end{document}
结果和以前一样。
答案2
我添加了siunitx
包和calc
库。
\documentclass[12pt,letterpaper]{article}
\usepackage[left=20mm,top=30mm,bottom=30mm,right=20mm]{geometry}
\usepackage{tikz} % for drawing pictures
\usetikzlibrary{arrows.meta,
calc,
chains,
positioning,
quotes,
shapes.geometric, arrows}
\usepackage{siunitx}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto,
node distance = 15mm and 19mm,
start chain = going right,
arr/.style = {->},>=Latex,
block/.style = {draw, minimum height=3em, minimum
width=4em,align=center,fill=blue!20},
sum/.style = {circle, draw, node contents={}},
]
\begin{scope}[nodes={on chain, join=by arr}]
\coordinate (in);
\node (n4) [block] {$K_m = \num{2e-1}$\\ \unit{\newton\meter\per\volt}};
\node (n5) [block] {$K_s = \num{5e-2}$ \\ \unit{\radian\per\newton\per\metre}};
\coordinate (out);
\end{scope}
\node [below=1pt of n4] {Motor};
\node [below=1pt of n5] {Spring};
\node at ($(in)!.5!(n4.west)$) [label={above:$V$}, label={below:\unit{\volt}}] {};
\node at ($(n4.east)!.5!(n5.west)$) [label={above:$T$}, label={below:\unit{\newton\meter}}] {};
\node at ($(n5.east)!.5!(out)$) [label={above:$\theta$}, label={below:\unit{\radian}}] {};
\end{tikzpicture}
\end{center}
\end{document}