内含矩阵的定位节点

内含矩阵的定位节点

我希望节点水平并排分布!并将节点对齐在顶部!但目前,它是重叠的。

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
    \begin{tikzpicture}[mymat/.style={matrix of nodes,
        nodes={draw,font=\sffamily\bfseries,text width=1em,
            text height=1em,baseline=center},
        column sep=-\pgflinewidth/2}]
    \node[mymat] (m0) {
        0 \\
    };
    \node[mymat,right=1cm of m0] (m1) {
        0 \\
        1 \\
    };
    \node[mymat,right=1cm of m1.west,anchor=west] (m2) {
        0 & 0 \\
        1 & 0 \\
        1 & 1 \\
        0 & 1 \\
    };
    \node[mymat,right=1cm of m2.west,anchor=west] (m3) {
    0 & 0 & 0\\
    1 & 0  & 0\\
    1 & 1  & 0\\
    0 & 1 & 0\\
    0 & 1 & 1\\
   1 & 1  & 1\\
   1 & 0  & 1\\
   0 & 0 & 1\\
};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

只需移除west锚点即可。您可以设置(和更改)node distance。这比每次都说 更容易right=1cm of ...

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
    \begin{tikzpicture}[mymat/.style={matrix of nodes,
        nodes={draw,font=\sffamily\bfseries,text width=1em,
            text height=1em,baseline=center},
        column sep=-\pgflinewidth/2},node distance=1cm]
    \node[mymat] (m0) {
        0 \\
    };
    \node[mymat,right=of m0] (m1) {
        0 \\
        1 \\
    };
    \node[mymat,right=of m1] (m2) {
        0 & 0 \\
        1 & 0 \\
        1 & 1 \\
        0 & 1 \\
    };
    \node[mymat,right=of m2] (m3) {
    0 & 0 & 0\\
    1 & 0  & 0\\
    1 & 1  & 0\\
    0 & 1 & 0\\
    0 & 1 & 1\\
   1 & 1  & 1\\
   1 & 0  & 1\\
   0 & 0 & 1\\
};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

如果要将它们对齐到顶部,请使用north eastnorth west锚点。

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
    \begin{tikzpicture}[mymat/.style={matrix of nodes,
        nodes={draw,font=\sffamily\bfseries,text width=1em,
            text height=1em,baseline=center},
        column sep=-\pgflinewidth/2},node distance=0.5cm]
    \node[mymat] (m0) {
        0 \\
    };
    \node[mymat,right=of m0.north east,anchor=north west] (m1) {
        0 \\
        1 \\
    };
    \node[mymat,right=of m1.north east,anchor=north west] (m2) {
        0 & 0 \\
        1 & 0 \\
        1 & 1 \\
        0 & 1 \\
    };
    \node[mymat,right=of m2.north east,anchor=north west] (m3) {
    0 & 0 & 0\\
    1 & 0  & 0\\
    1 & 1  & 0\\
    0 & 1 & 0\\
    0 & 1 & 1\\
   1 & 1  & 1\\
   1 & 0  & 1\\
   0 & 0 & 1\\
};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容