tikz边太长,如何控制节点的距离

tikz边太长,如何控制节点的距离

我在 beamer 类文档中有以下图表:

  \begin{center}

  \begin{tikzpicture} [auto]
    \tikzstyle{every node}=[font=\small]
    \tikzset{
      inst/.style={draw=black, rectangle},
      ref/.style={draw=black, circle}
    }
    \node[inst]                       (constant1) {ConstantNode};
    \node[right = of constant1]         (dummy1) {};
    \node[inst, right = of dummy1]       (constant2) {ConstantNode};

    \node[ref, below = of constant1]    (v1) {$v_1$};
    \node[below = of dummy1]            (dummy2) {};
    \node[ref, below = of constant2]    (v2) {$v_2$};

    \node[inst, below = of dummy2]       (phi) {$v_3 = \phi(v_1, v_2)$};
    \node[ref, below = of phi]          (v3) {$v_3$};    
    \node[inst, below = of v3]          (invoke) {MethodCallNode: $v_5$ = java/lang/String.substring(I), $v_3$, $v_4$};
    \node[ref, below = of invoke] (v5) {$v_5$};    
    \node[inst, below = of v5] (return) {ReturnNode $v_3$};


    \draw[->] (constant1) to (v1);
    \draw[->] (constant2) to (v2);
    \draw[->] (v1) to (phi);
    \draw[->] (v2) to (phi);    
    \draw[->] (phi) to (v3);    
    \draw[->] (v3) to (invoke);    
    \draw[->] (invoke) to (v5);    
    \draw[->] (v5) to (return);    

  \end{tikzpicture}
  \end{center}

但边太长,所以图表不适合页面。我怎样才能让它们变短?

答案1

\documentclass[12pt]{article}


\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{center}

  \begin{tikzpicture} [node distance=5mm]
    \tikzstyle{every node}=[font=\small]
    \tikzset{
      inst/.style={draw=black, rectangle},
      ref/.style={draw=black, circle}
    }
    \node[inst]                       (constant1) {ConstantNode};
    \node[right = of constant1]         (dummy1) {};
    \node[inst, right = of dummy1]       (constant2) {ConstantNode};

    \node[ref, below = of constant1]    (v1) {$v_1$};
    \node[below = of dummy1]            (dummy2) {};
    \node[ref, below = of constant2]    (v2) {$v_2$};

    \node[inst, below = of dummy2]       (phi) {$v_3 = \phi(v_1, v_2)$};
    \node[ref, below = of phi]          (v3) {$v_3$};    
    \node[inst, below = of v3]          (invoke) {MethodCallNode: $v_5$ = java/lang/String.substring(I), $v_3$, $v_4$};
    \node[ref, below = of invoke] (v5) {$v_5$};    
    \node[inst, below = of v5] (return) {ReturnNode $v_3$};


    \draw[->] (constant1) to (v1);
    \draw[->] (constant2) to (v2);
    \draw[->] (v1) to (phi);
    \draw[->] (v2) to (phi);    
    \draw[->] (phi) to (v3);    
    \draw[->] (v3) to (invoke);    
    \draw[->] (invoke) to (v5);    
    \draw[->] (v5) to (return);    

  \end{tikzpicture}

  \end{center}

  \end{document}

相关内容