21

I'm trying to put a boxed itemize list inside my TikZ figure:

\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}

But I get

! LaTeX Error: Something's wrong--perhaps a missing \item.` at the line `}};

and I don't understand why (since I have fed \itemize three \items.) Can anyone help?

1
  • Try \vbox instead of \framebox
    – user31034
    Jan 5, 2015 at 22:10

2 Answers 2

27

You need to use a \parbox, but since you probably want it to be the natural width of the text I used varwidth in the example below:

enter image description here

but I would recommend you use \nodes instead for each of the bulleted items, which makes it easier to connect them. To draw the box around the nodes you can use the fit library:

enter image description here

You can adjust the value of inner sep= to control the spacing between the text and the box.

Code:

\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}

Code: Suggested Solution

\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}
6
  • 1
    Thank you! Your suggested code is great... but how do I put a border around the bulleted list and ensure the arrows don't stray inside it?
    – xnx
    Jan 6, 2015 at 0:58
  • @xnx: Opps, sorry I missed that in the first version. Have updated to add a box around the nodes. Jan 6, 2015 at 1:16
  • How to remove frame here?
    – Y. zeng
    Oct 10, 2023 at 13:03
  • @Y.zeng: For that the node needs a 'draw=none'. Thus, changing the 'draw=brown' to 'draw=none' should do it. Oct 10, 2023 at 15:54
  • But the frame is created by \framebox
    – Y. zeng
    Oct 11, 2023 at 6:38
9

Do you want like this?

\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}
1
  • 2
    Using a \vbox totally rips my image apart. On the left side the vbox and on the right side the moved image.
    – Robert
    Oct 26, 2017 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .