我想使用 TikZ 创建一个简单的图表。下面的代码显示了一个我无法解决的问题:第一个节点的第二个和第三个单元格之间的间距(单词“某些条件”和列表之间的间距itemize
)与所有其他节点不同。请注意第一个节点指的是代码中首先定义的状态 2,而不是图片顶部的那个状态 1。我在表格中添加了一些行,以便更好地说明“某些文本”部分的问题。
似乎在 中添加更多空间topsep
会itemize
产生负面影响,而添加below=of orig
部分(参见注释行)以强制使用相同的语法不会改变任何内容。我该怎么做才能让第一个节点看起来与其他节点完全一样?
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{positioning}
\usepackage{enumitem}
\begin{document}
\begin{figure}%[!h]
\centering
\tikzset{line/.style={draw, thick, -latex', color=black}}
\tikzset{newbox/.style={rounded corners=1.75pt, very thick, minimum width=2.5cm, minimum height=1cm, text centered, draw=brown!90!black}}
\begin{tikzpicture}[node distance=1.0cm and 0.7cm, auto]
%\coordinate (orig) at (0,0);
%\node [newbox, below=of orig] (s2) {
\node [newbox] (s2) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 2}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\node [newbox, right=of s2] (s3) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 3}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\coordinate (mid) at ($(s2.north east)!0.5!(s3.north west)$);
\node [newbox, above=of mid] (s1) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 1}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\draw [line] (s1) -- (s2);
\draw [line] (s2) --++ (s3);
\draw [line] (s3) to [min distance=50pt,out=15,in=30,looseness=1] node[above] {otherwise} (s3);
\draw [line] (s3) to [loop above,looseness=4] node[above] {otherwise} (s3);
\draw [line] (s3.south) --++ (0cm,-0.5cm) -| (s2);
\end{tikzpicture}
\caption{MWE}
\label{fig:mwe}
\end{figure}
\end{document}
答案1
黑客:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows}
\usepackage{enumitem}
\begin{document}
\begin{figure}%[!h]
\centering
\mbox{}
\par
\tikzset{%
line/.style={draw, thick, -latex', color=black},
newbox/.style={rounded corners=1.75pt, very thick, minimum width=2.5cm, minimum height=1cm, text centered, draw=brown!90!black},
}
\begin{tikzpicture}[node distance=1.0cm and 0.7cm, auto]
\node [newbox] (s2) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 2}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\node [newbox, right=of s2] (s3) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 3}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\coordinate (mid) at ($(s2.north east)!0.5!(s3.north west)$);
\node [newbox, above=40pt of mid] (s1) {
\begin{tabular}{|l|}\hline
\multicolumn{1}{|c|}{\color{red}{\textsc{State 1}}}\\\hline
{some condition:}\\\hline
\parbox{5.6cm}{
\begin{itemize}[noitemsep,nolistsep,topsep=5pt]
\item Some Text
\item Some More Text Here
\end{itemize}
}\\\hline
\end{tabular}
};
\draw [line] (s1) -- (s2);
\draw [line] (s2) --++ (s3);
\draw [line] (s3) to [min distance=50pt,out=15,in=30,looseness=1] node[above] {otherwise} (s3);
\draw [line] (s3) to [loop above,looseness=4] node[above] {otherwise} (s3);
\draw [line] (s3.south) --++ (0cm,-0.5cm) -| (s2);
\end{tikzpicture}
\caption{MWE}
\label{fig:mwe}
\end{figure}
\end{document}