我想知道是否有可能在 latex 中复制下图中的 HMM。如果可以,应该对下面的代码进行哪些修改?任何帮助都将不胜感激。
请注意以下代码
\begin{tikzpicture}[
shorten >=1pt,
node distance=2cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state] (l_1) {$\ell_1$};
\node[state] (l_2) [right of=l_1] {$\ell_2$};
\node[state] (l_3) [right of=l_2] {$\ell_3$};
\node[state] (l_i) [above of=l_3] {$\ell_i$};
\node[state] (l_4) [right of=l_3] {$\ell_4$};
\node[state] (l_5) [right of=l_4] {$\ell_5$};
\node[state] (l_6) [right of=l_5] {$\ell_6$};
\node[state] (end) [right of=l_6] {$\ell_e$};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {1} (l_3)
(l_3) edge node {3/5} (l_i)
edge node [swap] {2/5} (l_4)
(l_i) edge node {3/5} (l_4)
edge [loop above] node {2/5} ()
(l_4) edge node [swap] {1} (l_5)
(l_5) edge node [swap] {1} (l_6)
(l_6) edge node [swap] {1} (end)
(end) edge [loop right] node {1} ();
\end{tikzpicture}
那么,我应该如何最好地在节点内包含多行乳胶?
答案1
将align=center
或添加align=left
到节点的选项中,例如单独显示,或通过样式显示多个。用于\\
换行。
\documentclass[10pt, border=20pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
shorten >=1pt,
node distance=2cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state, align=left] (l_1) {$\ell_1$\\A: $+1.16$\\T: $-0.22$};
\node[state] (l_2) [right of=l_1] {$\ell_2$};
\node[state] (l_3) [right of=l_2] {$\ell_3$};
\node[state] (l_i) [above of=l_3] {$\ell_i$};
\node[state] (l_4) [right of=l_3] {$\ell_4$};
\node[state] (l_5) [right of=l_4] {$\ell_5$};
\node[state] (l_6) [right of=l_5] {$\ell_6$};
\node[state] (end) [right of=l_6] {$\ell_e$};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {1} (l_3)
(l_3) edge node {3/5} (l_i)
edge node [swap] {2/5} (l_4)
(l_i) edge node {3/5} (l_4)
edge [loop above] node {2/5} ()
(l_4) edge node [swap] {1} (l_5)
(l_5) edge node [swap] {1} (l_6)
(l_6) edge node [swap] {1} (end)
(end) edge [loop right] node {1} ();
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,
shapes.geometric}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[
shorten >=1pt,
node distance=3cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state] (l_1) {
\begin{tabular}{c} \( A:1.16 \) \\ \( T:-0.22 \) \end{tabular}
};
\node[state] (l_2) [right of=l_1] {
\begin{tabular}{c} \( C:1.16 \) \\ \( G:-0.22 \) \end{tabular}
};
\node[state] (l_3) [right of=l_2] {
\begin{tabular}{c} \( A:1.16 \) \\ \( C:-0.22 \) \end{tabular}
};
\node[state] (l_i) [above of=l_3] {
\begin{tabular}{c} \( A:-0.22 \) \\ \( C:0.47 \) \\ \(G:-0.22\) \\ \(T:-0.22\) \end{tabular}
};
\node[state] (l_4) [right of=l_3] {
\begin{tabular}{c} \( A:1.39 \) \end{tabular}
};
\node[state] (l_5) [right of=l_4] {
\begin{tabular}{c} \( G:-0.22 \) \\ \( T:1.16 \) \end{tabular}
};
\node[state] (l_6) [right of=l_5] {
\begin{tabular}{c} \( C:1.16 \) \\ \( G:-0.22 \) \end{tabular}
};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {0} (l_3)
(l_3) edge node {-0.51} (l_i)
edge node [swap] {-0.92} (l_4)
(l_i) edge node {-0.51}
(l_4) edge [loop above] node {-0.92} ()
(l_4) edge node [swap] {0} (l_5)
(l_5) edge node [swap] {0} (l_6);
\end{tikzpicture}
\end{document}