
Jupyter Notebook Markdown에서 2개의 행렬을 작성하려고 하는데 2개의 행렬을 동일한 크기로 만드는 방법을 알 수 없습니다. 전체 크기를 변경할 수 있는지, 열 사이의 간격을 줄여서 보기 좋게 만들 수 있는지 모르겠습니다.
이것은 내 코드입니다.
$$ G_x = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix}$$
$$ G_y\begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix}$$
답변1
패키지에는 nicematrix
해당 문제에 대한 전용 기능이 있습니다.
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceMatrixBlock}[auto-columns-width]
First matrix
\[G_x = \begin{bNiceMatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bNiceMatrix}\]
and second matrix
\[G_y = \begin{bNiceMatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bNiceMatrix}\]
\end{NiceMatrixBlock}
\end{document}
여러 가지 편집이 필요합니다.
답변2
다음과 같은 가능성이 있습니다 blkarray
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray, bigstrut}
\begin{document}
\[
\begin{blockarray}{@{}r*{3}{r}}
\begin{block}{@{}c@{\enspace}[*{3}{r}]}
& -1 & -2 & -1 \bigstrut[t] \\
G_x = {}& 0 & 0 & 0 \\
& 1 & 2 & 1 \\
\end{block}\\[-1ex]
\begin{block}{@{}c@{\enspace}[*{3}{r}]}
& -1 & 0 & 1 \bigstrut[t] \\
G_y = {}& -2 & 0 & 2\\
& -1 & 0 & 1 \\
\end{block}
\end{blockarray}
\]
\end{document}
답변3
다음은 두 가지 추가 솔루션입니다.
\phantom{-}
더 많은 공백을 삽입하고 환경bmatrix*
대신 환경을 사용하려면 지시어를 사용하세요 .bmatrix
- 장점: 사용하기 쉬움
\phantom
단점: 너비를 미세 조정해야 하는 각 열마다 지시어 1개를 삽입해야 합니다.
맞춤형 환경 에서 패키지를 로드
siunitx
하고 해당 열 유형을 사용합니다.S
array
- 장점: 더 이상 미세 조정이 필요하지 않습니다.
- 단점: 쉽고 간단한 적용을 위해서는 열 유형이 상당히 단순해야 합니다.
\documentclass{article}
\usepackage{mathtools} % for 'bmatrix*' environment
\usepackage{siunitx} % for 'S' column type
\usepackage{array} % for '\newcolumntype' macro
\newcolumntype{T}{S[table-format=-1.0]} % <-- bespoke version of 'S' column type
\begin{document}
\begin{align*}
G_0 &=
\begin{bmatrix*}[r]
-1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1
\end{bmatrix*} \\
G_1 &=
\begin{bmatrix*}[r] % <-- note use of 'bmatrix*' env.
-1 & \phantom{-}0 & \phantom{-}1 \\ -2 & 0 & 2 \\ -1 & 0 & 1
\end{bmatrix*} \\
G_2 &=
\left[ \begin{array}{@{} TTT @{}} % <-- use the 'T' column type for all columns
-1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 % <-- note: no fine-tuning needed
\end{array}\right]
\end{align*}
\end{document}
답변4
와 함께 tabularray
:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\NewDocumentEnvironment{mymatrix}{+b}{
\begin{+bmatrix}[columns={1.3em, r, colsep=2pt}]
#1
\end{+bmatrix}
}{}
\begin{document}
\[
G_x =
\begin{mymatrix}
-1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1
\end{mymatrix}
\]
\[
G_y =
\begin{mymatrix}
-1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1
\end{mymatrix}
\]
\end{document}