Blockmatrix mit Überschriften

Blockmatrix mit Überschriften

Ich habe mit easybmat und blkarrary eine Matrix erstellt und möchte die Spalten über der Matrix beschriften. Dies ist der Code, den ich verwende, und so sieht die Matrix im Moment aus:

\usepackage{easybmat}
\usepackage{amsmath}
\usepackage{multirow,bigdelim}
\usepackage{blkarray}
\begin{document}
\[  \mathbb{X} =  \begin{array}{c@{}c} 
\left[   
\begin{blockarray}{cccccc}
\boldsymbol{\beta}  & x_1 & z_1 & \dots & z_{k-1}\\
\begin{BMAT}[3pt]{ccccc}{ccccccccc}
1 & x_{11} & 1 & \dots  & 0 \\   
1 & x_{21} & 1 & \dots  & 0 \\      
\vdots & \vdots &  \vdots & \ddots & \vdots \\     
1 & \vdots & 1 & \dots  & 0\\        
\vdots & & &  & \vdots \\ 
1  & \vdots & 0 & \dots  & 0\\   
1 & \vdots & 0 & \dots  & 0\\   
\vdots & \vdots & \vdots & \ddots & \vdots \\ 
1 & x_{n1} & 0 & \dots  & 0\\ 

\end{BMAT}   
\end{blockarray}

\right] 
&  
\begin{array}{l}  
\\[-17mm] \rdelim\}{4}{6mm}[$ \hspace{2mm} Category \hspace{2mm} 1$] \\ \\ 
\\[17mm]  \rdelim\}{4}{6mm}[$\hspace{2mm} Category \hspace{2mm} k$] \\ \\ 
\end{array} \\[-1ex] 
\end{array}  
\]
\end{document} 

Bildbeschreibung hier eingeben

Ich möchte, dass die erste Zeile in der aktuellen Matrix die Überschriften der Spalten enthält. Kann mir bitte jemand sagen, was ich falsch mache?

Antwort1

Hier ist, was mir eingefallen ist. Das einzige, was mir an dieser Lösung nicht gefällt, ist, dass ich sie \vphantomin der obersten Reihe der Matrix verwenden muss, damit die .northAnker ausgerichtet sind. Ich bin mir nicht sicher, wie ich das beheben und gleichzeitig die Grundlinie der Matrixelemente ausgerichtet halten kann. Wenn jemand anders eine Lösung hat, kann er sie gerne beisteuern.

Dieses kleine Ärgernis wurde behoben. Die Höhe eines Knotens in TikZ kann mit der text heightOption überschrieben werden. Das ist viel besser, als verwenden zu müssen \vphantom.

easybmatIch bin mit und nicht ganz vertraut blkarray, also habe ich mich stattdessen für Ti entschiedenkZ'- matrixBibliothek, mit der sich zusätzliche Funktionen ganz einfach in einer Matrix zeichnen lassen. Hier ist der Code für das, was Sie möchten:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{
  matrix,
  positioning,
  decorations,
  decorations.pathreplacing
}

\begin{document}
\begin{equation*}
  \mathbb{X} = 
\begin{tikzpicture}[baseline=(m.center)]
  \matrix (m) [
      matrix of math nodes,
      left delimiter={[},
      right delimiter={]},
      row 1/.style={nodes={text height=1ex}}
    ] {
      1      & x_{11} & 1       & \cdots & 0      \\
      1      & x_{21} & 1       & \cdots & 0      \\
      \vdots & \vdots &  \vdots & \ddots & \vdots \\
      1      & \vdots & 1       & \cdots & 0      \\
      \vdots &        &         &        & \vdots \\
      1      & \vdots & 0       & \cdots & 0      \\
      1      & \vdots & 0       & \cdots & 0      \\
      \vdots & \vdots & \vdots  & \cdots & \vdots \\
      1      & x_{n1} & 0       & \cdots & 0      \\
    };

    \node [above=1ex of m-1-1] {\(\boldsymbol{\beta}\)};
    \node [above=1ex of m-1-2] {\(x_{1}\)};
    \node [above=1ex of m-1-3] {\(z_{1}\)};
    % \node [above=1ex of m-1-4] {\\(\cdots\)};
    \node [above=1ex of m-1-5] {\(z_{k-1}\)};

    \draw [decoration={brace}, decorate] 
          ([xshift=3ex]m-1-5.north east) -- ([xshift=3ex]m-4-5.south east)
          node [pos=0.5, right=1ex] {Category 1};
    \draw [decoration={brace}, decorate] 
          ([xshift=3ex]m-6-5.north east) -- ([xshift=3ex]m-9-5.south east)
          node [pos=0.5, right=1ex] {Category \(k\)};
  \end{tikzpicture}
\end{equation*}
\end{document}

Ausgabe

Um das Problem mit der obersten Reihe speziell zu veranschaulichen, vergleichen Sie die folgenden beiden Bilder, die die Knotengrenzen zeigen.

Mit \vphantom: mit vphantom Ohne \vphantom: ohne vphantom

Der Vollständigkeit halber enthielt der ursprüngliche Code:

      right delimiter={]},
    ] {
      1      & \vphantom{1}x_{11} & 1       & \vphantom{1}\cdots & 0      \\
      1      & x_{21} & 1       & \cdots & 0      \\

Antwort2

Hier ist eine Lösung mit {bNiceMatrix}von nicematrix.

\documentclass{article}
\usepackage{amssymb} % for \mathbb
\usepackage{nicematrix}

\begin{document}

\begin{equation*}
\mathbb{X} = 
\begin{bNiceMatrix}[first-row,last-col=6]
      \beta  & x_1    & z_1     &        & z_{k-1} \\
      1      & x_{11} & 1       & \cdots & 0      & \Block{4-1}{\quad \text{Category 1}}\\
      1      & x_{21} & 1       & \cdots & 0      \\
      \vdots & \vdots &  \vdots & \ddots & \vdots \\
      1      & \vdots & 1       & \cdots & 0      \\
      \vdots &        &         &        & \vdots \\
      1      & \vdots & 0       & \cdots & 0      & \Block{4-1}{\quad \text{Category } k}\\
      1      & \vdots & 0       & \cdots & 0      \\
      \vdots & \vdots & \vdots  & \cdots & \vdots \\
      1      & x_{n1} & 0       & \cdots & 0      \\
\CodeAfter [sub-matrix/xshift=2mm]
  \SubMatrix{.}{1-1}{4-5}{\}}
  \SubMatrix{.}{6-1}{9-5}{\}}
\end{bNiceMatrix}
\end{equation*}

\end{document}

Ausgabe des obigen Codes

verwandte Informationen