![제목이 있는 블록 행렬](https://rvso.com/image/328812/%EC%A0%9C%EB%AA%A9%EC%9D%B4%20%EC%9E%88%EB%8A%94%20%EB%B8%94%EB%A1%9D%20%ED%96%89%EB%A0%AC.png)
easybmat 및 blkarrary를 사용하여 행렬을 만들었고 행렬 위의 열에 레이블을 지정하고 싶습니다. 이것은 내가 사용하고 있는 코드이며 현재 행렬의 모습은 다음과 같습니다.
\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}
현재 행렬의 첫 번째 행을 열의 제목으로 삼고 싶습니다. 누구든지 내가 뭘 잘못하고 있는지 지적해 주실 수 있나요?
답변1
내가 생각 해낼 수있는 것은 다음과 같습니다. 이 솔루션에서 내가 마음에 들지 않는 유일한 점은 앵커가 정렬 \vphantom
되도록 매트릭스의 맨 위 행에서 사용해야 한다는 것입니다 . .north
행렬 요소의 기준선을 계속 정렬하면서 이 문제를 해결하는 방법을 잘 모르겠습니다. 다른 사람이 해결책을 갖고 있다면 언제든지 의견을 제시해 주세요.
이 작은 성가심이 해결되었습니다. TikZ의 노드 높이는 옵션으로 덮어쓸 수 있습니다 text height
. 를 사용하는 것보다 훨씬 낫습니다 \vphantom
.
easybmat
나는 and 에 완전히 익숙하지 않아서 blkarray
대신 Ti를 사용하기로 결정했습니다.케이matrix
추가 기능을 행렬에 매우 쉽게 그릴 수 있는 Z' 라이브러리입니다. 원하는 코드는 다음과 같습니다.
\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}
맨 위 행의 문제를 구체적으로 설명하려면 노드 경계를 보여주는 다음 두 이미지를 비교하십시오.
완전성을 위해 원래 코드는 다음과 같습니다.
right delimiter={]},
] {
1 & \vphantom{1}x_{11} & 1 & \vphantom{1}\cdots & 0 \\
1 & x_{21} & 1 & \cdots & 0 \\
답변2
{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}