修复 tikz 中马尔可夫链的字体大小

修复 tikz 中马尔可夫链的字体大小

我正在绘制一个具有不同状态名称的大型马尔可夫链;一些状态包含数字,例如 (0,2),而一些状态则命名为 (S-1,R-1)。我正在尝试找到一种方法,让所有状态的字体大小都一致。具有 S 和 R 的状态比其他状态大。有没有办法让状态大小和字体大小一致?我的代码没有转换,如下所示

\documentclass{document}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes}
\usetikzlibrary{automata,}
\setlength{\jot}{7pt}
\usepackage{multirow}
\usepackage{latexsym}
\usepackage[utf8]{inputenc}
%\usepackage[dvipsnames]{xcolor}
\definecolor {processblue}{cmyk}{0,0,0,0.17}
\definecolor{light-gray}{gray}{0.85}
\newcommand*{\grayemph}[1]{%
  \tikz[baseline=(X.base)] \node[rectangle, fill=light-gray, rounded corners, inner sep=1.8mm] (X) {#1};%
}
\begin{document}
\begin{figure*}[t]
\centering
\begin{tikzpicture}
  \tikzset{
    >=stealth',
    node distance=1.5cm and 1.7cm ,on grid,
    every text node part/.style={align=center}
    state/.style={minimum size=30pt,font=\small,circle,draw},
    dots/.style={state,draw=none},
    edge/.style={->},
    trans/.style={font=\footnotesize,above=2mm},
    reflexive/.style={out=120,in=60,looseness=5,relative},
  }

\node[state] (C){$0,0$};
\node[state]       (v1)  [right =of C]   {$1,0$};
\node[state]       (v2)  [right =of v1]   {$2,0$};
\node[state]       (v3)  [right =of v2]   {$\cdots$};
\node[state]       (v4)  [right =of v3]   {\begin{scriptsize}S-1, {0}\end{scriptsize}};
\node[state]       (v5)  [right =of v4]   {$S,0$};

\node[state]       (v6)  [above =of C]   {$1,0$};
\node[state]       (v7)  [right =of v6]   {$1,1$};
\node[state]       (v8)  [right =of v7]   {$2,1$};
\node[state]       (v9)  [right =of v8]   {$\cdots$};
\node[state]       (v10)  [right =of v9]   {\begin{scriptsize}S-1, {0}\end{scriptsize}};;
\node[state]       (v11)  [right =of v10]   {$S,1$};
\node[state]       (v12)  [right =of v11]   {\begin{scriptsize}S+1, {0}\end{scriptsize}};; 

\node[state]       (v13)  [above =of v6]   {$\vdots$};
\node[state]       (v14)  [above =of v7]   {$\vdots$};
\node[state]       (v15)  [above =of v8]   {$\vdots$};
\node[state]       (v16)  [above =of v9]   {$\vdots$};
\node[state]       (v17)  [above =of v10]   {$\vdots$};
\node[state]       (v18)  [above =of v11]   {$\vdots$};
\node[state]       (v19)  [right =of v18]   {$\ddots$};

\node[state]       (v20)  [above =of v13]   {\begin{scriptsize}0,R-1\end{scriptsize}};
\node[state]       (v21)  [right =of v20]   {\begin{scriptsize}1,R-1\end{scriptsize}};
\node[state]       (v22)  [right =of v21]   {\begin{scriptsize}2,R-1\end{scriptsize}};
\node[state]       (v23)  [right =of v22]   {$\cdots$};
\node[state]       (v24)  [right =of v23]   {\begin{scriptsize}S-1, {R-1}\end{scriptsize}};;
\node[state]       (v25)  [right =of v24]   {\begin{scriptsize}S, {R-1}\end{scriptsize}};
\node[state]       (v26)  [right =of v25]   {\begin{scriptsize}S+1, {R-1}\end{scriptsize}};
\node[state]       (v27)  [right =of v26]   {$\cdots$};
\node[state]       (v28)  [right =of v27]  {\begin{scriptsize}S+R-1,R-1\end{scriptsize}};
\end{tikzpicture}
\caption{The Markov chain mode;.}

\end{figure*}
\end{document}

答案1

有些文本在里面scriptsize,而其他文本(用 $...$ 括起来的文本)不在里面。这导致字体大小不同。节点minimum size规范必须大于文本最长的节点,以便所有节点的大小相同(在此代码中,右上方节点的文本最长)。所以我也更改了最小尺寸规范。

再次,正如我之前在问题评论中所说,缺少的逗号似乎掩盖了规范state/.style。所以我在那里添加了一个逗号。只有那时 Tikz 才会读取该值

马尔可夫节点

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}
  \tikzset{
    >=stealth',
    node distance=2.5cm and 2.5cm ,on grid,
    every text node part/.style={align=center},
    state/.style={minimum width=2cm,
                  font=\small,
                  draw,
                  circle},
  }

\node[state] (C){$0,0$};
\node[state]       (v1)  [right =of C]   {$1,0$};
\node[state]       (v2)  [right =of v1]   {$2,0$};
\node[state]       (v3)  [right =of v2]   {$\cdots$};
\node[state]       (v4)  [right =of v3]   {\begin{scriptsize}S-1, {0}\end{scriptsize}};
\node[state]       (v5)  [right =of v4]  
        {\begin{scriptsize}S,0\end{scriptsize}};

\node[state]       (v6)  [above =of C]   {$1,0$};
\node[state]       (v7)  [right =of v6]   {$1,1$};
\node[state]       (v8)  [right =of v7]   {$2,1$};
\node[state]       (v9)  [right =of v8]   {$\cdots$};
\node[state]       (v10)  [right =of v9]   {\begin{scriptsize}S-1, {0}\end{scriptsize}};;
\node[state]       (v11)  [right =of v10]   {\begin{scriptsize}S,1\end{scriptsize}};
\node[state]       (v12)  [right =of v11]   {\begin{scriptsize}S+1, {0}\end{scriptsize}};; 

\node[state]       (v13)  [above =of v6]   {$\vdots$};
\node[state]       (v14)  [above =of v7]   {$\vdots$};
\node[state]       (v15)  [above =of v8]   {$\vdots$};
\node[state]       (v16)  [above =of v9]   {$\vdots$};
\node[state]       (v17)  [above =of v10]   {$\vdots$};
\node[state]       (v18)  [above =of v11]   {$\vdots$};
\node[state]       (v19)  [right =of v18]   {$\ddots$};

\node[state]       (v20)  [above =of v13]   {\begin{scriptsize}0,R-1\end{scriptsize}};
\node[state]       (v21)  [right =of v20]   {\begin{scriptsize}1,R-1\end{scriptsize}};
\node[state]       (v22)  [right =of v21]   {\begin{scriptsize}2,R-1\end{scriptsize}};
\node[state]       (v23)  [right =of v22]   {$\cdots$};
\node[state]       (v24)  [right =of v23]   {\begin{scriptsize}S-1, {R-1}\end{scriptsize}};;
\node[state]       (v25)  [right =of v24]   {\begin{scriptsize}S, {R-1}\end{scriptsize}};
\node[state]       (v26)  [right =of v25]   {\begin{scriptsize}S+1, {R-1}\end{scriptsize}};
\node[state]       (v27)  [right =of v26]   {$\cdots$};
\node[state]       (v28)  [right =of v27]  {\begin{scriptsize}S+R-1,R-1\end{scriptsize}};
\end{tikzpicture}
\end{document}

相关内容