
我有以下程式碼。
我想建立一個 tikz 矩陣,其中包含具有預定義預設形狀的節點。
但有時我想更改某些節點的形狀,在矩陣內部手動指定它。
我在 tikz 手冊中讀到,在節點文字前面編寫的任何帶有垂直線的程式碼都會傳遞到節點的程式碼。
因此,程式碼: 應該傳遞給第二個 Joe Doe 節點的程式碼。
|(shape = rectangle)|
但運行這個似乎不起作用。
\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 &[5cm]|(shape = rectangle)| John \linebreak Doe& \\[2cm]
& & &\\
};
\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 &[5cm]|[rectangle]| John \linebreak Doe& \\[2cm]
& & &\\
};
\draw[->] (a-1-1) -- (a-2-1);
\end{tikzpicture}
\end{document}