
Estoy tratando de escribir 2 matrices en Jupyter Notebook Markdown pero no puedo entender cómo hacer que las 2 matrices tengan el mismo tamaño. No sé si puedo cambiar todo el tamaño o reducir el espacio entre columnas para que se vea mejor.
Este es mi código:
$$ 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}$$
Respuesta1
El paquete nicematrix
tiene una función dedicada a ese problema.
\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}
Necesitas varias compilaciones.
Respuesta2
Una posibilidad con 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}
Respuesta3
Aquí hay dos soluciones adicionales:
usar
\phantom{-}
directivas para insertar más espacio y usar unbmatrix*
entorno en lugar de unbmatrix
entorno- pro: fácil de usar
- Desventaja: es necesario insertar 1
\phantom
directiva para cada columna cuyo ancho necesita ajuste
Cargue el
siunitx
paquete y use suS
tipo de columna en unarray
entorno personalizado.- pro: no se requieren más ajustes
- Desventaja: para una aplicación fácil y directa, los tipos de columnas deben ser bastante simples
\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}
Respuesta4
Con 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}