调整 Tikz 控制图形连接

调整 Tikz 控制图形连接

我的 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

使用用于定位图表节点的calcchains可以使控制图的代码显著缩短:

\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
...

相关内容