Creé una matriz usando easybmat y blkarrary y me gustaría etiquetar las columnas encima de la matriz. Este es el código que estoy usando y cómo se ve la matriz en este momento:
\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}
Me gustaría que la primera fila de la matriz actual sean los encabezados de las columnas. ¿Alguien puede señalar qué estoy haciendo mal, por favor?
Respuesta1
Esto es lo que se me ocurrió. Lo único que no me gusta de esta solución es que tengo que usarla \vphantom
en la fila superior de la matriz para que los .north
anclajes se alineen. No estoy seguro de cómo solucionarlo manteniendo alineada la línea base de los elementos de la matriz. Si alguien más tiene una solución, no dude en colaborar.
Esta pequeña molestia ha sido solucionada. La altura de un nodo en TikZ se puede sobrescribir con la text height
opción. Esto es mucho mejor que tener que usar \vphantom
.
No estoy completamente familiarizado con easybmat
y blkarray
, así que opté por usar TikBiblioteca Z' matrix
que permite dibujar características adicionales con bastante facilidad en una matriz. Aquí está el código de lo que quieres:
\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}
Para ilustrar específicamente el problema con la fila superior, compare las dos imágenes siguientes que muestran los límites de los nodos.
Para completar, el código original tenía:
right delimiter={]},
] {
1 & \vphantom{1}x_{11} & 1 & \vphantom{1}\cdots & 0 \\
1 & x_{21} & 1 & \cdots & 0 \\
Respuesta2
Aquí hay una solución con {bNiceMatrix}
of 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}