我曾尝试构建一个类似这样的 3D 盒子
但我最终
从此代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{automata}
\usetikzlibrary{shapes.geometric}
\tikzset{%
node distance=1cm,
every node/.style={%
align=center,
fill=white,
font=\small
},
elliptic state/.style={%
state,
ellipse,
inner sep=0cm,
minimum width=2cm
},
}
\begin{document}
\begin{center}
\begin{tikzpicture}[node distance=2cm,font=\scriptsize]
\node[elliptic state,accepting] (s1) {$s_1$: $m_a,m_b,m_c$};
\node[elliptic state,below left=of s1] (s2) {$s_2$: $m_a,\neg m_b,m_c$};
\node[elliptic state,below=0.6cm of s1] (s3) {$s_3$: $m_a,m_b,\neg m_c$};
\node[elliptic state,below right=of s1] (s4) {$s_4$: $\neg m_a,m_b,m_c$};
\node[elliptic state,below=0.6cm of s2] (s5) {$s_5$: $m_a,\neg m_b,\neg m_c$};
\node[elliptic state,below right=of s2] (s6) {$s_6$: $\neg m_a,\neg m_b,m_c$};
\node[elliptic state,below=0.6cm of s4] (s7) {$s_7$: $\neg m_a,m_b,\neg m_c$};
\node[elliptic state,below=0.6cm of s6] (s8) {$s_8$: $\neg m_a,\neg m_b,\neg m_c$};
\path (s1) edge node {$b$} (s2);
\path (s1) edge node {$c$} (s3);
\path (s1) edge node {$a$} (s4);
\path (s2) edge node {$c$} (s5);
\path (s2) edge node {$a$} (s6);
\path (s3) edge node {$c$} (s5);
\path (s3) edge node {$c$} (s7);
\path (s4) edge node {$c$} (s6);
\path (s4) edge node {$c$} (s7);
\path (s5) edge node {$c$} (s8);
\path (s6) edge node {$c$} (s8);
\path (s7) edge node {$c$} (s8);
\end{tikzpicture}
\end{center}
\end{document}
由于我的节点上有较多的文本,因此很难制作出一个看起来不杂乱的漂亮盒子。
我该如何调整我的盒子,让它看起来更好看?我的盒子很平,所以我想我需要让所有边的长度相等,并最终减少每个椭圆节点的顶部和底部填充,因为它占用了太多空间。
是否有任何 tikz 库可以自动创建这样的框以使其看起来更整洁?
答案1
这看起来怎么样?只是对节点定位和距离做了一些更改,添加了换行符并减小了字体大小。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{automata,shapes.geometric}
\tikzset{%
node distance=1cm,
every node/.style={%
align=center,
fill=white,
font=\small
},
elliptic state/.style={%
state,
ellipse,
inner sep=0cm,
minimum width=2cm
},
}
\begin{document}
\begin{center}
\begin{tikzpicture}[node distance=2cm]
\node[elliptic state,accepting] (s1) {$s_1$:\\ $m_a,m_b,m_c$};
\node[elliptic state,below left=of s1] (s2) {$s_2$:\\ $m_a,\neg m_b,m_c$};
\node[elliptic state,below=3cm of s1] (s3) {$s_3$:\\ $m_a,m_b,\neg m_c$};
\node[elliptic state,right=of s1] (s4) {$s_4$:\\ $\neg m_a,m_b,m_c$};
\node[elliptic state,below=3cm of s2] (s5) {$s_5$:\\ $m_a,\neg m_b,\neg m_c$};
\node[elliptic state,right=of s2] (s6) {$s_6$:\\ $\neg m_a,\neg m_b,m_c$};
\node[elliptic state,below=3cm of s4] (s7) {$s_7$:\\ $\neg m_a,m_b,\neg m_c$};
\node[elliptic state,below=3cm of s6] (s8) {$s_8$:\\ $\neg m_a,\neg m_b,\neg m_c$};
\path (s1) edge node {$b$} (s2);
\path (s1) edge node {$c$} (s3);
\path (s1) edge node {$a$} (s4);
\path (s2) edge node {$c$} (s5);
\path (s2) edge node {$a$} (s6);
\path (s3) edge node {$c$} (s5);
\path (s3) edge node {$c$} (s7);
\path (s4) edge node {$c$} (s6);
\path (s4) edge node {$c$} (s7);
\path (s5) edge node {$c$} (s8);
\path (s6) edge node {$c$} (s8);
\path (s7) edge node {$c$} (s8);
\end{tikzpicture}
\end{center}
\end{document}