如何使 TikZ 中的所有节点大小相同?

如何使 TikZ 中的所有节点大小相同?

我画了一个 TikZ 图形,但遇到了两个问题。第一个问题是,由于节点内文本的大小,所有节点的大小都不同。我在这里的其他问题中读到,要使它们相等,需要指定最小大小,但这似乎对我不起作用。我有这样的情况:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}

\begin{document}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2.5cm,scale=1, transform shape,align=center,minimum size=3em]

    \node[state]    (MP)                                {more \\points};  
    \node[state]    (BP)    [right=of MP]               {better \\pointers};
    \node[state]    (GS)    [below=of $(MP)!0.5!(BP)$]  {game \\signal};
    \node[state]    (SO)    [below left=of GS]          {stressed \\out};
    \node[state]    (CO)    [below right=of GS]         {contribute};
    \node[state]    (GT)    [below=of $(SO)!0.5!(CO)$]  {great \\time};

    \path[->] (MP) edge node {} (GS)
              (BP) edge node {} (GS)
              (GS) edge node {} (SO)
              (GS) edge node {} (CO)
              (SO) edge node {} (GT)
              (CO) edge node {} (GT);

    \end{tikzpicture}
\end{figure}

\end{document}

我只是希望所有节点都具有相同的大小,当然这取决于文本最大的节点。但我该如何实现呢?

此外,我当前的图形不是那么对称。stressed out节点应与对齐more points,并且contribute应与对齐better pointers。但它们分别在左边和右边一点。有什么想法如何对齐它们吗?

答案1

您只需要修复一个足够大的最小尺寸,但应用于state,而不是 tikzpicutre:

    state/.style={circle, draw, minimum size=2cm}

通过改变绘图顺序可以获得对称性:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}

\begin{document}

\begin{figure}%[H]
    \centering
    \begin{tikzpicture}[>=stealth', shorten >=1pt, auto,
    node distance=2.5cm, scale=1, 
    transform shape, align=center, 
    state/.style={circle, draw, minimum size=2cm}]

    \node[state]    (MP) {more \\points};  
    \node[state, below right=of MP] (GS) {game \\signal};
    \node[state, above right=of GS] (BP) {better \\pointers};
    \node[state, below left=of GS] (SO) {stressed \\out};
    \node[state, below right=of GS] (CO) {contribute};
    \node[state, below right=of SO] (GT) {great \\time};

    \path[->] (MP) edge node {} (GS)
              (BP) edge node {} (GS)
              (GS) edge node {} (SO)
              (GS) edge node {} (CO)
              (SO) edge node {} (GT)
              (CO) edge node {} (GT);

    \end{tikzpicture}
\end{figure}

\end{document}

在此处输入图片描述

答案2

您可以使用minimum size=6em

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}

\begin{document}

\tikzset{bignode/.style={red, draw=blue, fill=yellow!20, minimum size=6em,}}


{
    \centering
    \begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2.5cm,scale=1, transform shape,align=center,minimum size=3em]

    \node[state,bignode]     (MP)                                {more \\points};  
    \node[state,bignode]     (BP)    [right=of MP]               {better \\pointers};
    \node[state,bignode]     (GS)    [below=of $(MP)!0.5!(BP)$]  {game \\signal};
    \node[state,bignode]     (SO)    [below left=of GS]          {stressed \\out};
    \node[state,bignode]     (CO)    [below right=of GS]         {contribute};
    \node[state,bignode]     (GT)    [below=of $(SO)!0.5!(CO)$]  {great \\time};

    \path[->] (MP) edge node {} (GS)
              (BP) edge node {} (GS)
              (GS) edge node {} (SO)
              (GS) edge node {} (CO)
              (SO) edge node {} (GT)
              (CO) edge node {} (GT);

    \end{tikzpicture}

}

\end{document}

在此处输入图片描述

相关内容