我的 Tikz 图形有这个问题:
如你所见,不同的标签靠得很近,甚至进入一些块内,你可以纠正它,尽量使整个集合尽可能等距
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows.meta,positioning,quotes}
\newcommand\ppbb{path picture bounding box}
\tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=4em]
\tikzstyle{sum} = [draw, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {$\frac{1}{Ls+R}$};
\node [block, right of=controller] (kt) {$k_t$};
\node [block, right of=kt, node distance=2cm] (system) {$sist$};
\node [output, right of=system] (output) {};
\node [block, below of=kt] (measurements) {$k_e$};
\draw [draw,->] (input) -- node {$V(s)$} (sum);
\draw [->] (sum) -- node {} (controller);
\draw [->] (controller) -- node {$I(s)$} (kt);
\draw [->] (kt) -- node[name=u] {$T(s)$} (system);
\draw [->] (system) -- node [name=y] {$\Omega(s)$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (measurements) -| node[pos=1.00] {$-$}
node [near end] {$E(s)$} (sum);
\end{tikzpicture}
\end{document}
[1]: https://i.stack.imgur.com/RhVmn.png
答案1
您加载了该positioning
包,但没有使用它的功能。
不要
right of=xxx
写 ,而要写right=of xxx
,其余部分也一样。相反
right=of sum
,写right=of input
。
现在,方框间距相等且对称。如需其他调整,
node distance
为全球变化而改变。用于
right=15mm of xxx
个别改变。如果需要的话还有
xshift=...
和yshift=...
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows.meta,positioning,quotes}
\newcommand\ppbb{path picture bounding box}
\tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=4em]
\tikzstyle{sum} = [draw, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node [input, name=input] {};
\node [sum, right=of input] (sum) {};
\node [block, right=of input] (controller) {$\frac{1}{Ls+R}$};
\node [block, right=of controller] (kt) {$k_t$};
\node [block, right=of kt] (system) {$sist$};
\node [output, right=of system] (output) {};
\node [block, below=of kt] (measurements) {$k_e$};
\draw [draw,->] (input) -- node {$V(s)$} (sum);
\draw [->] (sum) -- node {} (controller);
\draw [->] (controller) -- node {$I(s)$} (kt);
\draw [->] (kt) -- node[name=u] {$T(s)$} (system);
\draw [->] (system) -- node [name=y] {$\Omega(s)$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (measurements) -| node[pos=1.00] {$-$}
node [near end] {$E(s)$} (sum);
\end{tikzpicture}
\end{document}
答案2
使用用于定位图表节点的calc
库chains
可以使控制图的代码显著缩短:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning,
quotes}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[
node distance = 6mm and 12mm,
start chain = going right,
%
dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt,
node contents={}},
box/.style = {draw, minimum height=2em, minimum width=3em},
sum/.style = {circle, draw, minimum size=6mm, inner sep=0pt,
node contents={$+$}},
arr/.style = {-Stealth}
]
% nodes in main branch organised in chain
\begin{scope}[nodes={on chain, join=by arr}]
\coordinate (in) ;
\node (sum) [sum];
\node (cntrl) [box] {$\dfrac{1}{Ls+R}$};
\node (kt) [box] {$k_t$};
\node (sys) [box] {\emph{system}};
\coordinate (out);
\end{scope}
\node (dot) [dot,
at={($(sys.east)!0.5!(out)$)},
label=above:$\Omega(s)$];
% feedback node
\node (fb) [box, below=of kt] {$k_e$};
% connections not consider in "join" macro
\draw[arr] (dot) |- (fb)
(fb) -| (sum) node[pos=0.75, left] {$E(s)$}
node[pos=0.98, left] {$-$};
% labels as quotes on nodes connections
\path (in) to["$V(s)$"] (sum)
(cntrl) to["$I(s)$"] (kt)
(kt) to["$T(s)$"] (sys);
\end{tikzpicture}
\end{document}
笔记:
- 被
chains
视为positioning
库语法,因此node distance=6mm and 12mmm
确定节点之间的垂直距离(在主分支和反馈分支中)和主分支中节点之间的水平距离。 - 图像元素的样式由 的选项决定
tikzpicture
。它们可以tikzset
在例如序言中收集:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning,
quotes}
\usepackage{amsmath}
\tikzset{
dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt,
node contents={}},
box/.style = {draw, minimum height=2em, minimum width=3em},
sum/.style = {circle, draw, minimum size=6mm, inner sep=0pt,
node contents={$+$}},
arr/.style = {-Stealth}
}
ment}
\begin{tikzpicture}[
node distance = 6mm and 12mm,
start chain = going right,
]
% nodes in main branch
...