我正在尝试将一个盒装itemize
列表放入我的 Ti 中钾Z 形:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\node at (1.7, 10) {\texttt{q1}};
\node at (1.7, 8) {\texttt{q2}};
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 10) -- (5, 10);
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 9) -- (5, 8.8);
\node at (5, 10) {\framebox{\Large
{\begin{itemize}
\item \texttt{[0]}
\item \texttt{[1]}
\item \texttt{[2]}
\end{itemize}}
}};
\end{tikzpicture}
\end{document}
但我明白
! LaTeX Error: Something's wrong--perhaps a missing \item.` at the line `}};
我不明白为什么(因为我已经喂了\itemize
三个\item
s。)有人可以帮忙吗?
答案1
您需要使用\parbox
,但因为您可能希望它是我varwidth
在下面的示例中使用的文本的自然宽度:
但我建议您\nodes
对每个项目符号使用 ,这样可以更轻松地连接它们。要围绕节点绘制框,您可以使用以下fit
库:
您可以调整的值来inner sep=
控制文本和框之间的间距。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{varwidth}
\begin{document}
\begin{tikzpicture}
\node at (1.7, 10) {\texttt{q1}};
\node at (1.7, 8) {\texttt{q2}};
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 10) -- (5, 10);
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 9) -- (5, 8.8);
\node at (5, 10) {\framebox{\Large
{\begin{varwidth}{\linewidth}\begin{itemize}
\item \texttt{[0]}
\item \texttt{[1]}
\item \texttt{[2]}
\end{itemize}\end{varwidth}}
}};
\end{tikzpicture}
\end{document}
代码:建议的解决方案
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
\node (Q1) at (1.7, 10) {\texttt{q1}};
\node (Q2) at (1.7, 8) {\texttt{q2}};
\node [font=\Large] (top) at (5,10) {$\bullet$ [0]};
\node [font=\Large] (middle) at (5,9) {$\bullet$ [1]};
\node [font=\Large] (bottom) at (5,8) {$\bullet$ [2]};
\node[draw=brown, thick,fit={(top) (middle) (bottom)}, inner sep=10pt] (box) {};
\draw [-{>[length=3mm,width=3mm]}, red, line width=1pt] (Q1) -- (top);
\draw [-{>[length=3mm,width=3mm]}, blue,line width=1pt] (Q2) -- (middle);
\end{tikzpicture}
\end{document}
答案2
你想要這樣嗎?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\node at (1.7, 10) {\texttt{q1}};
\node at (1.7, 8) {\texttt{q2}};
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 10) -- (5, 10);
\draw [-{>[length=3mm,width=3mm]},line width=1pt] (2, 9) -- (5, 8.8);
\node [draw] at (5, 10) {\vbox {\Large
{\begin{itemize}
\item \texttt{[0]}
\item \texttt{[1]}
\item \texttt{[2]}
\end{itemize}}
}};
\end{tikzpicture}
\end{document}