tikz 행렬의 노드에서 텍스트를 정의하는 방법

tikz 행렬의 노드에서 텍스트를 정의하는 방법

다음 코드가 있습니다.

앰퍼샌드 기호 사이에 텍스트를 추가하여 노드에 텍스트를 추가하고 싶습니다. 이를 수행하는 구문은 무엇입니까?

예를 들어 두 번째 열의 첫 번째 행에 "John Doe"라는 텍스트를 추가하려고 합니다. 텍스트에는 John과 Doe 사이에 줄 바꿈이 포함되어야 합니다. 내가 사용하는 일반적인 구문은 다음과 같습니다.

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

행렬 옵션의 노드를 미리 정의한 행렬에서 이 작업을 어떻게 수행합니까?

\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

노드에 고정을 지정하면 줄 바꿈을 추가할 수 있습니다. 예를 들어:

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

여기에 이미지 설명을 입력하세요

관련 정보