我在使用 TikZ 绘制控制系统框图时遇到了一些麻烦。我希望某个节点显示为一个点,表示连接。但是,这个点不是位于节点的中心,而是位于其上方。我该如何解决这个问题?
从该 LaTeX 文档生成的 PS 或 PDF 中可以明显看出这个问题:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [draw, rectangle, minimum width = 0.75cm, minimum height = 0.75cm]
\tikzstyle{sum} = [draw, circle, minimum size=.5cm, node distance=1.75cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{tikzpicture}[node distance=2cm,auto,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (a1) {$A_1(s)$};
\node [block, right of=a1] (a2) {$A_2(s)$};
\node [block, right of=a2] (k) {$K$};
\node [output, right of=k] (output) {};
\draw [->] (a1) -- (a2);
\draw [->] (a2) -- node [name=vout] {$V_o$} (k);
\node [block, below of=a2] (a3) {$A_1(s)$};
\draw [draw,->, node] (input) -- node {$V_\mathrm{ref}$} node[pos=0.95] {{\tiny $+$}} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- node[name=vl] {$V_L$} (output);
\draw [->] (vl) |- (a3);
\draw [->] (a3) -| node[pos=0.99, right] {{\tiny $-$}} (sum);
\fill (vl) circle [radius=2pt];
\end{tikzpicture}
\end{document}
答案1
您可以使用
\fill (vl.south) circle [radius=2pt];
或者更好的是,
\fill (vl|-k) circle [radius=2pt];
完整示例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [draw, rectangle, minimum width = 0.75cm, minimum height = 0.75cm]
\tikzstyle{sum} = [draw, circle, minimum size=.5cm, node distance=1.75cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{tikzpicture}[node distance=2cm,auto,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (a1) {$A_1(s)$};
\node [block, right of=a1] (a2) {$A_2(s)$};
\node [block, right of=a2] (k) {$K$};
\node [output, right of=k] (output) {};
\draw [->] (a1) -- (a2);
\draw [->] (a2) -- node [name=vout] {$V_o$} (k);
\node [block, below of=a2] (a3) {$A_1(s)$};
\draw [draw,->] (input) -- node {$V_\mathrm{ref}$} node[pos=0.95] {{\tiny $+$}} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- node[name=vl] {$V_L$} (output);
\draw [->] (vl) |- (a3);
\draw [->] (a3) -| node[pos=0.99, right] {{\tiny $-$}} (sum);
%\fill (vl.south) circle [radius=2pt];
\fill (vl|-k) circle [radius=2pt];
\end{tikzpicture}
\end{document}
另一种选择是先V_L
在适当的位置设置一个坐标,然后使用该坐标放置圆圈:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [draw, rectangle, minimum width = 0.75cm, minimum height = 0.75cm]
\tikzstyle{sum} = [draw, circle, minimum size=.5cm, node distance=1.75cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{tikzpicture}[node distance=2cm,auto,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (a1) {$A_1(s)$};
\node [block, right of=a1] (a2) {$A_2(s)$};
\node [block, right of=a2] (k) {$K$};
\node [output, right of=k] (output) {};
\draw [->] (a1) -- (a2);
\draw [->] (a2) -- node [name=vout] {$V_o$} (k);
\node [block, below of=a2] (a3) {$A_1(s)$};
\draw [draw,->] (input) -- node {$V_\mathrm{ref}$} node[pos=0.95] {{\tiny $+$}} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- coordinate[label=above:$V_L$] (vl) (output);
\draw [->] (vl) |- (a3);
\draw [->] (a3) -| node[pos=0.99, right] {{\tiny $-$}} (sum);
\fill (vl) circle [radius=2pt];
\end{tikzpicture}
\end{document}
另一个选择是使用坐标(如上面最后一个例子所示),然后使用*->
箭头类型,并为 指定一个方便的值shorten
,如
\draw [->] (k) -- coordinate[label=above:$V_L$] (vl) (output);
\draw [*->,shorten <= -2pt] (vl) |- (a3);
完整示例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [draw, rectangle, minimum width = 0.75cm, minimum height = 0.75cm]
\tikzstyle{sum} = [draw, circle, minimum size=.5cm, node distance=1.75cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{tikzpicture}[node distance=2cm,auto,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (a1) {$A_1(s)$};
\node [block, right of=a1] (a2) {$A_2(s)$};
\node [block, right of=a2] (k) {$K$};
\node [output, right of=k] (output) {};
\draw [->] (a1) -- (a2);
\draw [->] (a2) -- node [name=vout] {$V_o$} (k);
\node [block, below of=a2] (a3) {$A_1(s)$};
\draw [draw,->] (input) -- node {$V_\mathrm{ref}$} node[pos=0.95] {{\tiny $+$}} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- coordinate[label=above:$V_L$] (vl) (output);
\draw [*->,shorten <= -2pt] (vl) |- (a3);
\draw [->] (a3) -| node[pos=0.99, right] {{\tiny $-$}} (sum);
\end{tikzpicture}
\end{document}
答案2
这里最好使用坐标来区分节点和交叉点
\draw [draw,->, node] (input) -- node {$V_\mathrm{ref}$} node[pos=0.95] {{\tiny $+$}} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- node[name=vl] {$V_L$} (output);
\draw [->] (vl) |- (a3);
\draw [->] (a3) -| node[pos=0.99, right] {{\tiny $-$}} (sum);
\fill (vl) circle [radius=2pt];
答案3
这里和有所不同coordinate
。node
我修改了代码。我使用了/.style
和,并且用不同的方法放置{\tiny $+$}
。我认为符号的位置更好。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[%
node distance = 2 cm,auto,>=latex',
block/.style = {draw, rectangle, minimum width = 0.75cm, minimum height = 0.75cm},
sum/.style = {draw, circle, minimum size=.5cm, node distance=1.75cm},
input/.style = {coordinate},
output/.style = {coordinate},
dot/.style = {anchor=base,fill,circle,inner sep=1pt}]
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (a1) {$A_1(s)$};
\node [block, right of=a1] (a2) {$A_2(s)$};
\node [block, right of=a2] (k) {$K$};
\node [output, right of=k] (output) {};
\node [block, below of=a2] (a3) {$A_1(s)$};
\draw [->] (a1) -- (a2);
\draw [->] (a2) -- node [name=vout] {$V_o$} (k);
\draw [draw,->] (input) -- node {$V_\mathrm{ref}$} (sum);
\draw [->] (sum) -- (a1);
\draw [->] (k) -- coordinate[dot](vl) node {$V_L$} (output);
\draw [->] (vl) |- (a3);
\draw [->] (a3) -| (sum);
\node [shift=({145:12pt})] at (sum.center) {\tiny $+$}; % I removed {}
\node [shift=({-45:12pt})] at (sum.center) {\tiny $-$};
\end{tikzpicture}
\end{document}