0

I have the following piece of code.

I want to add text to my nodes by simply adding the text between the ampersand symbols. What is the syntax to do this?

For example I try to add the text "John Doe" in the 1st row of the second column. The text must contain a line break between John and Doe. The usual syntax I would use would be something like:

\node[draw, align = center]{John \\ Doe};

How would do this in a matrix in which I predefined the nodes in the matrice's options?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture} \matrix(a)[matrix of nodes , nodes in empty cells , nodes = {draw , circle , align = center} , column sep={1cm,between origins} , row sep = {1cm , between origins}] { & John \ Doe & & \ & & &\ };

\draw[->] (a-1-1) -- (a-2-1);

\end{tikzpicture} \end{document}

1 Answers1

2

If you give your nodes a fixed with, you can add line breaks. For example:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture} \matrix(a)[ matrix of nodes, nodes in empty cells, nodes={draw, circle, align=center, text width=0.8cm}, column sep={1.5cm, between origins}, row sep={1.5cm, between origins} ]{ & John \linebreak Doe & & \ & & &\ };

\draw[->] (a-1-1) -- (a-2-1);

\end{tikzpicture} \end{document}

enter image description here