
Ich versuche, 2 Matrizen in Jupyter Notebook Markdown zu schreiben, aber ich kann nicht herausfinden, wie ich die 2 Matrizen auf die gleiche Größe bringen kann. Ich weiß nicht, ob ich die gesamte Größe ändern oder den Abstand zwischen den Spalten verringern kann, damit es besser aussieht.
Dies ist mein Code:
$$ 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}$$
Antwort1
Das Paket nicematrix
verfügt über eine Funktion, die sich speziell diesem Problem widmet.
\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}
Man braucht mehrere Zusammenstellungen.
Antwort2
Eine Möglichkeit mit 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}
Antwort3
Hier sind zwei zusätzliche Lösungen:
Verwenden Sie
\phantom{-}
Anweisungen, um mehr Leerzeichen einzufügen, und verwenden Sie einebmatrix*
Umgebung anstelle einerbmatrix
Umgebung- Pro: einfach zu bedienen
\phantom
Nachteil: Für jede Spalte, deren Breite feinabgestimmt werden muss, muss eine Direktive eingefügt werden
Laden Sie das
siunitx
Paket und verwenden Sie seinenS
Spaltentyp in einer maßgeschneidertenarray
Umgebung- Pro: keine Feinabstimmung mehr nötig
- Nachteil: Für eine einfache und unkomplizierte Anwendung müssen die Spaltentypen relativ einfach sein
\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}
Antwort4
Mit 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}