带有标签、花括号和突出显示的矩阵。

带有标签、花括号和突出显示的矩阵。

努力创建与附图类似的矩阵。有什么建议吗?在此处输入图片描述

答案1

另一种tikz \matrix方法是使用复制红色虚线。由于方括号和花括号的形状(请参阅编辑以获得更好的解决方案)。

\documentclass[tikz]{standalone}

\usetikzlibrary{fit,matrix,positioning,decorations.pathreplacing}

\begin{document}
    \begin{tikzpicture}
        \matrix (m) [matrix of nodes,column sep={2.5em,between origins},row sep = {2em,between origins}]
        {
                      & {$ t_1 $} & {$ t_2 $} & {$ t_3 $} & {$ t_4 $} & {$ t_5 $} & {$ t_6 $} \\
            {$ N_1 $} & {0} & {1} & {0} & {1} & {0} & {1} \\
            {$ N_2 $} & {1} & {0} & {1} & {1} & {1} & {1} \\
            {$ N_3 $} & {1} & {1} & {0} & {0} & {1} & {0} \\
            {$ N_4 $} & {0} & {0} & {1} & {1} & {1} & {1} \\
            {$ N_5 $} & {0} & {0} & {0} & {1} & {1} & {0} \\
        };

        \begin{scope}[every node/.style={draw=red,dashed,inner sep = 1pt}]
            \node[fit={(m-2-2) (m-6-3)}]{};
            \node[fit={(m-2-4) (m-6-5)}]{};
            \node[fit={(m-2-6) (m-6-7)}]{};
        \end{scope}

        \node[fit={(m-2-2) (m-6-7)},inner sep = 3pt] (bracemat){};

        \begin{scope}[line width = .8pt]
            % Square braces
            \draw[line width = .8pt] ([xshift=-0.25em]bracemat.north east) -- (bracemat.north east) -- (bracemat.south east) -- ([xshift=-0.25em]bracemat.south east);
            \draw[line width = .8pt] ([xshift=0.25em]bracemat.north west) -- (bracemat.north west) -- (bracemat.south west) -- ([xshift=0.25em]bracemat.south west);

            % Curly braces
            \begin{scope}[decoration={brace,amplitude=0.25em},every node/.style={above=0.25em}]
                \draw[decorate] (m-1-2.north west) -- node{$ t_1 $} (m-1-3.north east);
                \draw[decorate] (m-1-4.north west) -- node{$ t_2 $} (m-1-5.north east);
                \draw[decorate] (m-1-6.north west) -- node{$ t_3 $} (m-1-7.north east);
            \end{scope}
        \end{scope}

    \end{tikzpicture}
\end{document}

编辑:这个解决方案稍微简单一些,并且与数学模式中的其他矩阵更加一致。

\documentclass[tikz]{standalone}

\usetikzlibrary{fit,matrix,positioning}

\begin{document}
    \begin{tikzpicture}[every matrix/.style={column sep = {2em,between origins},row sep={2em,between origins}}]
        \matrix (m) [matrix of nodes,left delimiter={[},right delimiter={]}]
        {
            {0} & {1} & {0} & {1} & {0} & {1} \\
            {1} & {0} & {1} & {1} & {1} & {1} \\
            {1} & {1} & {0} & {0} & {1} & {0} \\
            {0} & {0} & {1} & {1} & {1} & {1} \\
            {0} & {0} & {0} & {1} & {1} & {0} \\
        };

        \matrix (m2) [matrix of nodes,left=0.4em of m]
        {
            {$ N_1 $} \\
            {$ N_2 $} \\
            {$ N_3 $} \\
            {$ N_4 $} \\
            {$ N_5 $} \\
        };

        \matrix (m3) [matrix of nodes,above=-0.4em of m]
        {
            {$ t_1 $} & {$ t_2 $} & {$ t_3 $} & {$ t_4 $} & {$ t_5 $} & {$ t_6 $} \\
        };

        \begin{scope}[every node/.style={draw=red,dashed,inner sep = 1pt}]
            \node[fit={(m-1-1) (m-5-2)}]{};
            \node[fit={(m-1-3) (m-5-4)}]{};
            \node[fit={(m-1-5) (m-5-6)}]{};
        \end{scope}

        \path (m3-1-1.north west) --node[yshift=0.1em,rotate=90]{$ \Bigg\rbrace $} node[yshift=1em]{$ t_1 $} (m3-1-2.north east);
        \path (m3-1-3.north west) --node[yshift=0.1em,rotate=90]{$ \Bigg\rbrace $} node[yshift=1em]{$ t_2 $} (m3-1-4.north east);
        \path (m3-1-5.north west) --node[yshift=0.1em,rotate=90]{$ \Bigg\rbrace $} node[yshift=1em]{$ t_3 $} (m3-1-6.north east);

    \end{tikzpicture}
\end{document}

新的结果是:

在此处输入图片描述

答案2

像这样?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blkarray, bigstrut}
\usepackage{mathtools}
\usepackage[usestackEOL]{stackengine}

\begin{document}

\[ \bigstrutjot = 1.5ex\begin{blockarray}{*{7}{c}}
& \BAmulticolumn{2}{c}{\Vectorstack{t_1\\\overbrace{\hspace*{2.8em}}}} & \BAmulticolumn{2}{c}{\Vectorstack{t_2\\\overbrace{\hspace*{2.8em}}}} & \BAmulticolumn{2}{c}{\Vectorstack{t_3\\\overbrace{\hspace*{2.8em}}}}\\[-1.25ex]
& t_1 & t_2 & t_3 & t_4 & t_5 & t_6 \\[-0.5ex]
  \begin{block}{c[*{6}{c}]}%
N_1 &\bigstrut[t] 0 & 1 & 0 & 1 & 0 & 1 \\
N_2 &1 & 0 & 1 & 1 & 1 & 1 \\
N_3 & 1 & 1 & 0 & 0 & 1 & 0 \\
N_3 & 0 & 0 & 1 & 1 & 1 & 1 \\
N_5 & 0 & 0 & 0 & 1 & 1 & 0\bigstrut[b] \\
\end{block}
\end{blockarray} \]

\end{document}

在此处输入图片描述

添加pstricks:带有虚线框的代码:

    \documentclass[svgnames]{article}
    \usepackage{blkarray, bigstrut}
    \usepackage{mathtools}
    \usepackage[usestackEOL]{stackengine}
    \usepackage{pst-node} 
    \usepackage{auto-pst-pdf} 

    \begin{document}

    \bigstrutjot = 1.5ex
 \begin{pspicture}
    $\displaystyle\begin{blockarray}{*{7}{c}}
    & \BAmulticolumn{2}{c}{\Vectorstack{t_1\\\overbrace{\hspace*{2.8em}}}} & \BAmulticolumn{2}{c}{\Vectorstack{t_2\\\overbrace{\hspace*{2.8em}}}} & \BAmulticolumn{2}{c}{\Vectorstack{t_3\\\overbrace{\hspace*{2.8em}}}}\\[-1.25ex]
    & t_1 & t_2 & t_3 & t_4 & t_5 & t_6 \\[-0.5ex]
      \begin{block}{c[*{6}{c}]}%
    N_1 &\bigstrut[t]\pnode[-0.4ex, 2.3ex]{C1} 0 & 1 &\pnode[-1ex, 2.3ex]{C2} 0 & 1 & \pnode[-0.8ex, 2.3ex]{C3} 0 & 1 \\
    N_2 &1 & 0 & 1 & 1 & 1 & 1 \\
    N_3 & 1 & 1 & 0 & 0 & 1 & 0 \\
    N_3 & 0 & 0 & 1 & 1 & 1 & 1 \\
    N_5 & 0 & 0 \pnode[0.8ex, -0.8ex]{D1} & 0 & 1 \pnode[1ex, -0.8ex]{D2} & 1 & 0 \pnode[0.6ex, -0.8ex]{D3} \bigstrut[b] \\
    \end{block}
    \end{blockarray} $
    \psset{linestyle=dashed, linecolor=Tomato, framearc=0.2, dash=5pt 5pt}
    \foreach \i in {1,2,3}{\psframe(C\i)(D\i)}
    \end{pspicture}

    \end{document}

在此处输入图片描述

答案3

与。{NiceTabular}nicematrix

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\renewcommand{\arraystretch}{1.2}

\begin{NiceTabular}{ccccccc}
   & t1 & t2 & t3 & t4 & t5 & t6 \\
N1 & 0 & 1 & 0 & 1 & 0 & 1 \\
N2 & 1 & 0 & 1 & 1 & 1 & 1 \\
N3 & 1 & 1 & 0 & 0 & 1 & 0 \\
N4 & 0 & 0 & 1 & 1 & 1 & 1 \\
N5 & 0 & 0 & 0 & 1 & 1 & 0 
\CodeAfter
  \SubMatrix[{2-2}{last-last}][extra-height=1mm,xshift=1mm]
  \OverBrace[shorten]{1-2}{1-3}{t1}
  \OverBrace[shorten]{1-4}{1-5}{t2}
  \OverBrace[shorten]{1-6}{1-7}{t3}
  \tikz [dashed,red]
    \draw ([shift={(-1mm,1mm)}]2-2.north west) rectangle ([shift={(1mm,-1mm)}]last-3.south east) 
          ([shift={(-1mm,1mm)}]2-4.north west) rectangle ([shift={(1mm,-1mm)}]last-5.south east) 
          ([shift={(-1mm,1mm)}]2-6.north west) rectangle ([shift={(1mm,-1mm)}]last-7.south east) ; 
\end{NiceTabular}

\end{document}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

相关内容