
행과 열에 레이블이 지정된 대괄호로 묶인 행렬을 만들려고 합니다. 내 시도는 다음과 같습니다
\begin{equation}
\begin{aligned}
&\begin{array}{*{7}{p{.8cm}}}
\mathcal{G}^{\{1\}} & \mathcal{G}^{\{2\}} & \mathcal{G}^{\{3\}} & \mathcal{G}^{\{4\}} & \mathcal{G}^{\{5\}} & e_{r1} & e_{r2}\end{array}\\
\begin{array}{r}
\text{plant (out)}\\
n_1\\
n_2\\
\text{plant (in)}\end{array} & \left[\begin{array}{*{7}{p{.8cm}}}
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0\end{array}\right]
\end{aligned}
\end{equation}
그러나 이렇게 하면 "LaTeX 오류: \mathcal은 수학 모드에서만 허용됩니다."라는 오류가 많이 발생합니다. 및 "$ 누락이 삽입되었습니다." 내 서문에는 배열과 amsmath 패키지가 모두 포함되어 있습니다. 이것이 작동하지 않는 이유는 무엇이며 이를 달성하는 가장 좋은 방법은 무엇입니까? $$를 추가하면 "\begin{array} 뒤에 예기치 않은 $" 오류가 발생합니다.
답변1
열의 내용은 p
기본적으로 텍스트 모드에서 처리됩니다. 자동 줄바꿈이 필요하지 않은 것 같으므로 p
열 유형을 패키지 w
에서 제공 array
하고 길이 매개변수(열의 디자인 너비)를 인수로 사용하는 열 유형으로 바꾸는 것이 좋습니다 .
\documentclass{article}
\usepackage{array} % for 'w' column type
\usepackage{amsmath} % for 'aligned' env.
\newcommand\mG[1]{\mathcal{G}^{\{#1\}}} % handy shortcut macro
\begin{document}
\begin{equation}
\begin{aligned}
&\kern4pt
\begin{array}{ *{6}{wl{8mm}} r }
\mG{1} & \mG{2} & \mG{3} & \mG{4} & \mG{5} & e_{r1} & e_{r2}
\end{array} \\
\begin{array}{r}
\text{plant (out)}\\
n_1\\
n_2\\
\text{plant (in)}
\end{array}
&\left[
\begin{array}{ *{6}{wl{8mm}} r }
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0\\
0 & 0 & -1 & -1 & -1 & -1 & 0
\end{array}
\right]
\end{aligned}
\end{equation}
\end{document}
답변2
을 사용하는 것이 좋습니다 nicematrix
.
\documentclass{article}
\usepackage{amsmath} % for 'aligned' env.
\usepackage{nicematrix}
\newcommand\cG[1]{\mathcal{G}}
\begin{document}
\begin{equation}
\begin{bNiceArray}[first-row,first-col]{*{7}{w{c}{2em}}}
& \cG^{\{1\}} & \cG^{\{2\}} & \cG&{\{3\}} & \cG^{\{4\}} & \cG^{\{5\}} & e_{r1} & e_{r2} \\
\text{plant (out)} & 0 & 0 & -1 & -1 & -1 & -1 & 0 \\
n_1 & 0 & 0 & -1 & -1 & -1 & -1 & 0 \\
n_2 & 0 & 0 & -1 & -1 & -1 & -1 & 0 \\
\text{plant (in)} & 0 & 0 & -1 & -1 & -1 & -1 & 0
\end{bNiceArray}
\end{equation}
\end{document}
w{c}{2em}
고정 너비 열을 얻으십시오 .