删除空节点中的空格,以便绘制线连接

删除空节点中的空格,以便绘制线连接

我试图删除由于转到空节点而导致的两行之间的空白。具体来说,我在空节点的左侧绘制一个节点,然后将空节点绘制到一个新的完整节点。

我已经在节点上使用了 inner sep=0 和 outer sep=0 来减少空隙。然而,仍然有一小块碎片残留。

由于空间原因,我需要在那里有一个空节点。

图像: 空位置

梅威瑟:

\documentclass{article}
\usepackage{tikz}%pictures
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{tikzpicture}[auto,>=latex'] 
    \tikzstyle{block} = [draw, shape=rectangle, minimum height=3em, minimum width=3em, node distance=2cm, line width=1pt]
    \tikzstyle{sum} = [draw, shape=circle, node distance=1.5cm, line width=1pt, minimum width=1.25em]
    \tikzstyle{connection}=[inner sep=0,outer sep=0]
 %Creating Blocks and Connection Nodes
\node [block, right of=input] (h1) {$0.99$};
 \node [right of=h1] (hsum) {};
    \node [connection, right of=hsum] (cont) {};
    \path (h1) -- coordinate (hmed) (h1);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (input) -- (h1);\draw (h1) -- (cont);
    \end{scope}
 %Creating Blocks and Connection Nodes
\node [block, right of=cont] (m1) {$0.18$};\node [block, right of=m1] (m2) {$0.16$};
 \node [right of=m2] (msum) {};
    \node [connection, right of=msum] (output) {};
    \path (m1) -- coordinate (mmed) (m2);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (cont) -- (m1);\draw (m1) -- (m2);\draw (m2) -- (output);
    \end{scope}
 \end{tikzpicture}
\end{document}

答案1

您可以使用coordinate类似

\coordinate[right of=hsum] (cont);

代码:

\documentclass{article}
\usepackage{tikz}%pictures
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{tikzpicture}[auto,>=latex']
    \tikzstyle{block} = [draw, shape=rectangle, minimum height=3em, minimum width=3em, node distance=2cm, line width=1pt]
    \tikzstyle{sum} = [draw, shape=circle, node distance=1.5cm, line width=1pt, minimum width=1.25em]
    \tikzstyle{connection}=[inner sep=0,outer sep=0]
 %Creating Blocks and Connection Nodes
 \coordinate (input);
\node [block, right of=input] (h1) {$0.99$};
 \node [right of=h1] (hsum) {};
    \coordinate[right of=hsum] (cont);
    \path (h1) -- coordinate (hmed) (h1);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (input) -- (h1);\draw (h1) -- (cont);
    \end{scope}
 %Creating Blocks and Connection Nodes
\node [block, right of=cont] (m1) {$0.18$};\node [block, right of=m1] (m2) {$0.16$};
 \node [right of=m2] (msum) {};
    \node [connection, right of=msum] (output) {};
    \path (m1) -- coordinate (mmed) (m2);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (cont) -- (m1);\draw (m1) -- (m2);\draw (m2) -- (output);
    \end{scope}
 \end{tikzpicture}
\end{document}

在此处输入图片描述

如果您想要坚持使用node,请使用cont.center连接而不是cont类似:

\draw (input) -- (h1);\draw (h1) -- (cont.center);

再次编码:

\documentclass{article}
\usepackage{tikz}%pictures
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{tikzpicture}[auto,>=latex']
    \tikzset{block/.style = {draw, shape=rectangle, minimum height=3em, minimum width=3em, node
                              distance=2cm, line width=1pt},
              sum/.style = {draw, shape=circle, node distance=1.5cm, line width=1pt, minimum 
                            width=1.25em},
              connection/.style={inner sep=0,outer sep=0}
    }
 %Creating Blocks and Connection Nodes
 \coordinate (input);
\node [block, right of=input] (h1) {$0.99$};
 \node [right of=h1] (hsum) {};
    \node [connection, right of=hsum] (cont) {};
    \path (h1) -- coordinate (hmed) (h1);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (input) -- (h1);\draw (h1) -- (cont.center);
    \end{scope}
 %Creating Blocks and Connection Nodes
\node [block, right of=cont] (m1) {$0.18$};\node [block, right of=m1] (m2) {$0.16$};
 \node [right of=m2] (msum) {};
    \node [connection, right of=msum] (output) {};
    \path (m1) -- coordinate (mmed) (m2);
    %Connecting Blocks
    \begin{scope}[line width=1pt]
         \draw (cont.center) -- (m1);\draw (m1) -- (m2);\draw (m2) -- (output);
    \end{scope}
 \end{tikzpicture}
\end{document}

另外,像我在第二段代码中所做的那样,使用(已弃用)tikzset而不是(已弃用)。tikzstyle

答案2

您可以通过添加一些属性来实现这一点,tikzpicture如下所示:

\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]

相关内容