我想在一个“tikzpicture”中并排绘制两个带有文本的框,由于我是 tikz 的新手,我设法做到了这一点(MWE),您能帮助我实现它吗,我将不胜感激。
以下是 MWE:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (example-align) [draw,very thick, align=left,text width=7.5em]{Machine \\ \hspace{0.4cm} variables \\\hspace{0.4cm} invariants \\\hspace{0.4cm} theorems \\\hspace{0.4cm} variant \\\hspace{0.4cm} events}; &
\end{tikzpicture}
\hspace{1.4cm}
\begin{tikzpicture}
\node (example-align) [draw,very thick, align=left,text width=7.5em] {Context \\ \hspace{0.4cm} carrier sets \\\hspace{0.4cm} constants \\\hspace{0.4cm} axioms \\ \hspace{0.4cm} theorems};
\end{tikzpicture}
\end{document}
答案1
一种可能性是tikzpicture
包含两个框:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}% for positioning of nodes
\begin{document}
\begin{tikzpicture}[
node distance = 0mm and 12mm,% for distance between nodes
box/.style = {draw, very thick, minimum width=5em}% nodes style
]
\node (n1) [box] {\begin{tabular}{ll}% text in nodes write as table
\multicolumn{2}{l}{Machine} \\
& variables \\
& invariants \\
& theorems \\
& variant \\
& events
\end{tabular}};
\node (n2) [box, below right=of n1.north east]
{\begin{tabular}{ll}
\multicolumn{2}{l}{Context} \\
& carrier sets \\
& constants \\
& axioms \\
& theorems
\end{tabular}};
\end{tikzpicture}
\end{document}
答案2
你的直觉是正确的:把两个节点放在一张图片中。幸运的是,这很简单。
我将使用该positioning
库来定位相对于第一个节点的第二个节点。我还将使用它enumitem
来创建自定义列表环境,而不是在第一行之后的每一行开头手动插入空格。
例如,
\documentclass[border=10pt]{standalone}
\usepackage{tikz, enumitem}
\usetikzlibrary{positioning}
\newlist{myalign}{itemize}{1}
\setlist[myalign]{label=,leftmargin=4mm,labelwidth=*,nosep}
\begin{document}
\begin{tikzpicture}
[
my text node/.style={draw, very thick, align=left, text width=7.5em}
]
\node (example-align) [my text node] {Machine\\\begin{myalign} \item variables \item invariants \item theorems \item variant \item events\end{myalign}};
\node (example-align2) [my text node, right=1.4cm of example-align.north east, anchor=north west] {Context\\\begin{myalign} \item carrier sets \item constants \item axioms \item theorems\end{myalign}};
\end{tikzpicture}
\end{document}
north east
我使用和作为锚点将列表对齐到顶部north west
。如果您希望它们对齐到底部,则可以使用south east
和south west
,或者对于垂直居中,可以不指定锚点或仅使用east
和west
。