
Tengo el siguiente fragmento de código.
Quiero agregar texto a mis nodos simplemente agregando el texto entre los símbolos comerciales. ¿Cuál es la sintaxis para hacer esto?
Por ejemplo, intento agregar el texto "John Doe" en la primera fila de la segunda columna. El texto debe contener un salto de línea entre John y Doe. La sintaxis habitual que usaría sería algo como:
\node[draw, align = center]{John \\ Doe};
¿Cómo haría esto en una matriz en la que predefiní los nodos en las opciones de la matriz?
\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}
Respuesta1
Si le da a sus nodos un valor fijo, puede agregar saltos de línea. Por ejemplo:
\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}