Horizontale Abstände zwischen den Bmatrix-Elementen in der Ausrichtungsumgebung

Horizontale Abstände zwischen den Bmatrix-Elementen in der Ausrichtungsumgebung

Ich habe in meinem Dokument eine große Blockmatrix, die den Seitenrand leicht verletzt. Ich möchte den horizontalen Abstand zwischen den Matrixelementen einer Zeile verringern. Außerdem möchte ich mehrere Gleichungen ausrichten. Ich habe es mit Array und Matrix versucht, aber der arraycolsepBefehl funktioniert nicht wie erwartet.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{array}

\begin{document}
The following very large matrix could fit the text width if the spacing could be reduced slightly.
\setcounter{MaxMatrixCols}{30}
\begin{align}
x =& 
  \begin{bmatrix}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{bmatrix}\\
=& 3
\end{align}
This could be done defining the arraycolsep:
\begin{align}
\setlength\arraycolsep{4pt}
x =
  \begin{bmatrix}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{bmatrix}\\
\end{align}
Unfortunately, as soon as I try to align multiple lines the arracolsep command stops doing what I expect.

\begin{align}
\setlength\arraycolsep{4pt}
x =& 
  \begin{bmatrix}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{bmatrix}\\
=& 3
\end{align}
As is the same for the array env

\begin{align}
\setlength\arraycolsep{4pt}
x =& 
  \left[\begin{array}{cccccccccccccccccccccccc}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{array}\right]\\
=& 3
\end{align}
Can anyone help out? Thanks!

\end{document}

Bildbeschreibung hier eingeben

Edit 1: Ich habe vergessen zu erwähnen, dass ich in der zweiten Zeile eine sehr kurze Gleichung verwendet habe. Allerdings ist die zweite Zeile auch sehr lang und beides passt nicht in eine einzige Zeile.

Antwort1

Ich würde eine varmatrixUmgebung definieren, in der Sie sowohl die \arraycolsepals auch die Schriftgröße festlegen können.

Dies ist wesentlich flexibler, da Sie sich für \normalsizeeine Reduzierung des Abstands, aber auch für die Verwendung kleinerer Größen entscheiden können.

Der Standardwert ist \smallund 0.7\arraycolsep.

\documentclass{article}
\usepackage{amsmath}

\newsavebox{\varmatrixbox}

\ExplSyntaxOn
\keys_define:nn {martin/varmatrix}
 {
  sep   .dim_set:N = \l_martin_varmatrix_sep_dim,
  delim .tl_set:N  = \l_martin_varmatrix_delim_tl,
  size  .tl_set:N  = \l_martin_varmatrix_size_tl,
  sep   .initial:n = 0.7\arraycolsep,
  size  .initial:n = \small,
 }

\NewDocumentEnvironment{varmatrix}{O{}}
 {
  \keys_set:nn {martin/varmatrix} { #1 }
  \begin{lrbox}{\varmatrixbox}
  % font size
  \l_martin_varmatrix_size_tl
  % separation
  \setlength{\arraycolsep}{\l_martin_varmatrix_sep_dim}
  $\begin{\l_martin_varmatrix_delim_tl matrix}
 }
 {
  \end{\l_martin_varmatrix_delim_tl matrix}$
  \end{lrbox}
  \vcenter{\box\varmatrixbox}
 }
\ExplSyntaxOff

\setcounter{MaxMatrixCols}{50}

\begin{document}

\begin{align}
x &=
  \setlength{\arraycolsep}{3pt}
  \begin{bmatrix}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{bmatrix}\\
  &=
  \begin{varmatrix}[delim=b,size=\normalsize,sep=3pt]
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{varmatrix}\\
  &=
  \begin{varmatrix}[delim=b,size=\small]
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{varmatrix}\\
  &=
  \begin{varmatrix}[delim=p,size=\footnotesize,sep=0.5\arraycolsep]
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{varmatrix}
\end{align}

\end{document}

Bildbeschreibung hier eingeben

Einige Erklärungen.

  • Der \keys_define:nnTeil definiert eine Schlüssel-Wert-Syntax für die Optionen bis varmatrix.

    1. Mit der sepTaste wird die\arraycolsep
    2. der delimSchlüssel setzt die Zäune, verwenden Sie die Standardbuchstaben amsmath, b, p, v, Voder sogar nichts für keinen Zaun
    3. der sizeSchlüssel sollte eine Schriftgrößenangabe enthalten
  • Die varmatrixUmgebung setzt die Matrix in eine Box, daher müssen wir den Mathematikmodus neu starten, nachdem wir die Größe und die\arraycolsep

  • Nachdem die Box fertig ist, dient sie im Inneren \vcenterzur vertikalen Zentrierung wie übliche Matrizen

Antwort2

Ich schlage vor, das Spielen mit \arraycolsep und die Verwendung einer mittelgroßen Matrix (80 % der Anzeigestilgröße) zu kombinieren, wie im nccmathPaket definiert:

    \documentclass[12pt]{article}
    \usepackage{amsmath, nccmath}
    \usepackage{etoolbox}
    \AtBeginEnvironment{bmatrix}{\setlength{\arraycolsep}{4pt}}
    \setcounter{MaxMatrixCols}{30}

    \begin{document}
    The following very large matrix fits the text width using medsize matrices

    \begin{align}
    x &=
      \medmath{\begin{bmatrix}
        1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
        0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
        0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
      \end{bmatrix}}\\
    &= 3
    \end{align}

    \end{document}

Bildbeschreibung hier eingeben

Antwort3

@{}Sie können mit der Syntax für einen 4pt-Abstand zwischen den Spalten einfügen matrix. Verwenden Sie für einen korrekten Abstand auch &=not .=&

Bildbeschreibung hier eingeben

\begin{align}
x &= 
  \left[\begin{array}{*{24}{c@{\hspace{4pt}}}}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0
  \end{array}\right]\\
&= 3
\end{align}

verwandte Informationen