使同一图像中的节点大小不同

使同一图像中的节点大小不同

我想让所有节点都大小相同。但问题是其中一些节点包含更多文本,因此它们会自动变大。任何帮助都将不胜感激。

代码

\begin{tikzpicture}
  [scale=.5,auto=left,every node/.style={circle,inner sep=0pt, fill=blue!20}]  
  \node (n1) at (-5,1) {$v_{1}$}; 
  \node (n2) at (-5,6) {$v_{i}$};
  \node (n3) at (-5,11) {$v_{n}$};
  \node (n4) at (1,-5) {$u_{1}$}; 
  \node (n5) at (6,-5) {$u_{j}$};
  \node (n6) at (11,-5) {$u_{n}$};
  \node (n7) at (1,1) {$(u_{1},v_{1})$}; 
  \node (n8) at (1,6) {$(u_{1},v_{i})$};
  \node (n9) at (1,11) {$(u_{1},v_{n})$};

  \node (n10) at (6,1) {$(u_{j},v_{1})$}; 
  \node (n11) at (6,6) {$(u_{j},v_{i})$};
  \node (n12) at (6,11) {$(u_{j},v_{n})$};

  \node (n13) at (11,1) {$(u_{m},v_{1})$}; 
  \node (n14) at (11,6) {$(u_{m},v_{i})$};
  \node (n15) at (11,11) {$(u_{m},v_{n})$};

\foreach \from/\to in {n2/n3,n1/n2,n4/n5,n5/n6,n7/n8,n8/n9,n10/n11,n11/n12,n13/n14,n14/n15,n9/n12,n12/n15,n8/n11,n11/n14,n7/n10,n10/n13}
\draw[loosely dotted] (\from) -- (\to);
   \path [every node/.style={font=\scriptsize, inner sep=+.1667em}] 
        (n1) edge [bend left]  node[swap] {} (n3)
        (n4) edge [bend right]  node[swap] {} (n6)
        (n9) edge [bend right]  node[swap] {$a$} (n7)
        (n7) edge [bend right]  node[swap] {$b$} (n13)              (n13) edge [bend right]  node[swap] {$c$} (n15)
        (n15) edge [bend right]  node[swap] {$d$} (n9);
\end{tikzpicture}

答案1

您可以设置一个minimum size值:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  [scale=.5,auto=left,every node/.style={circle,inner sep=0pt, fill=blue!20,minimum size=39pt}]  
  \node (n1) at (-5,1) {$v_{1}$}; 
  \node (n2) at (-5,6) {$v_{i}$};
  \node (n3) at (-5,11) {$v_{n}$};
  \node (n4) at (1,-5) {$u_{1}$}; 
  \node (n5) at (6,-5) {$u_{j}$};
  \node (n6) at (11,-5) {$u_{n}$};
  \node (n7) at (1,1) {$(u_{1},v_{1})$}; 
  \node (n8) at (1,6) {$(u_{1},v_{i})$};
  \node (n9) at (1,11) {$(u_{1},v_{n})$};

  \node (n10) at (6,1) {$(u_{j},v_{1})$}; 
  \node (n11) at (6,6) {$(u_{j},v_{i})$};
  \node (n12) at (6,11) {$(u_{j},v_{n})$};

  \node (n13) at (11,1) {$(u_{m},v_{1})$}; 
  \node (n14) at (11,6) {$(u_{m},v_{i})$};
  \node (n15) at (11,11) {$(u_{m},v_{n})$};

\foreach \from/\to in {n2/n3,n1/n2,n4/n5,n5/n6,n7/n8,n8/n9,n10/n11,n11/n12,n13/n14,n14/n15,n9/n12,n12/n15,n8/n11,n11/n14,n7/n10,n10/n13}
\draw[loosely dotted] (\from) -- (\to);
   \path [every node/.style={font=\scriptsize, inner sep=+.1667em}] 
        (n1) edge [bend left]  node[swap] {} (n3)
        (n4) edge [bend right]  node[swap] {} (n6)
        (n9) edge [bend right]  node[swap] {$a$} (n7)
        (n7) edge [bend right]  node[swap] {$b$} (n13)              (n13) edge [bend right]  node[swap] {$c$} (n15)
        (n15) edge [bend right]  node[swap] {$d$} (n9);
\end{tikzpicture}

\end{document}

在此处输入图片描述

positioning也许您会对帮助您放置没有明确坐标的节点的库感兴趣。

带有库的代码positioning

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
  [scale=.5,auto=left,every node/.style={circle,inner sep=0pt, fill=blue!20,minimum size=38pt},node distance=1.35cm and 1.35cm]  

  \node (n7) at (1,1) {$(u_{1},v_{1})$}; 
  \node[above=of n7] (n8) {$(u_{1},v_{i})$};
  \node[above=of n8] (n9) {$(u_{1},v_{n})$};

  \node[right=of n7] (n10) {$(u_{j},v_{1})$}; 
  \node[above=of n10] (n11) {$(u_{j},v_{i})$};
  \node[above=of n11] (n12) {$(u_{j},v_{n})$};

  \node[right=of n10] (n13) {$(u_{m},v_{1})$}; 
  \node[above=of n13] (n14) {$(u_{m},v_{i})$};
  \node[above=of n14] (n15) {$(u_{m},v_{n})$};

  \node[left=of n7] (n1) {$v_{1}$}; 
  \node[above=of n1] (n2)  {$v_{i}$};
  \node[above=of n2] (n3) {$v_{n}$};

  \node[below=of n7] (n4) {$u_{1}$}; 
  \node[right=of n4] (n5)  {$u_{j}$};
  \node[right=of n5] (n6) {$u_{n}$};

\foreach \from/\to in {n2/n3,n1/n2,n4/n5,n5/n6,n7/n8,n8/n9,n10/n11,n11/n12,n13/n14,n14/n15,n9/n12,n12/n15,n8/n11,n11/n14,n7/n10,n10/n13}
\draw[loosely dotted] (\from) -- (\to);
   \path [every node/.style={font=\scriptsize, inner sep=+.1667em}] 
        (n1) edge [bend left]  node[swap] {} (n3)
        (n4) edge [bend right]  node[swap] {} (n6)
        (n9) edge [bend right]  node[swap] {$a$} (n7)
        (n7) edge [bend right]  node[swap] {$b$} (n13)              (n13) edge [bend right]  node[swap] {$c$} (n15)
        (n15) edge [bend right]  node[swap] {$d$} (n9);
\end{tikzpicture}

\end{document}

相关内容