我正在实验 tikz 的矩阵形状:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[matrix, rotate=0, yshift=0cm, column sep=0.2cm, minimum width=10cm, minimum height=10cm] (SIMDATA) {
\draw[rectangle,draw=red,fill=gray,minimum width=0.6cm, minimum height=5.8cm] {}; &
\draw[rectangle,draw=blue,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; &
\draw[rectangle,draw=green,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; &
\draw[rectangle,draw=yellow,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; \\
};
\end{tikzpicture}
\end{document}
我原本希望上面的代码能够生成四个垂直放置的条形图,排列成一行,这就是我将矩形嵌套在 tikz 矩阵中的原因。但是代码没有生成任何内容,没有错误,也没有警告:
我的代码有什么问题吗?
答案1
\draw
用于绘制路径,例如\draw (0,0) -- (1,1);
。你似乎想要\node
:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[matrix, rotate=0, yshift=0cm, column sep=0.2cm, minimum width=10cm, minimum height=10cm] (SIMDATA) {
\node[rectangle,draw=red,fill=gray,minimum width=0.6cm, minimum height=5.8cm] {}; &
\node[rectangle,draw=blue,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; &
\node[rectangle,draw=green,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; &
\node[rectangle,draw=yellow,fill=gray,minimum width=0.6cm, minimum height=5.8cm]{}; \\
};
\end{tikzpicture}
\end{document}