Matriz de espaciado horizontal en entorno de alineación

Matriz de espaciado horizontal en entorno de alineación

Tengo una matriz de bloques grande en mi documento, que viola ligeramente el margen de la página. Me gustaría reducir el espacio horizontal entre los elementos de la matriz de una fila. Además, quiero alinear varias ecuaciones. Intenté con matriz y matriz pero el arraycolsepcomando no funciona como esperaba.

\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}

ingrese la descripción de la imagen aquí

Edición 1: olvidé mencionar que utilicé una ecuación muy corta en la segunda línea. Sin embargo, la segunda línea también es muy larga y ambas no caben en una sola línea.

Respuesta1

Definiría un varmatrixentorno en el que puedas establecer tanto el \arraycolseptamaño como el de fuente.

Esto es mucho más flexible, porque puedes decidir \normalsizereducir la separación, pero también utilizar un tamaño más pequeño.

El valor predeterminado es \smally 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}

ingrese la descripción de la imagen aquí

Algunas explicaciones.

  • La \keys_define:nnparte define una sintaxis clave-valor para las opciones varmatrix.

    1. la sepllave establece el\arraycolsep
    2. la delimclave establece las vallas, use las letras estándar de amsmath, b, p, vo Vincluso nada para ninguna valla
    3. la sizeclave debe recibir una declaración del tamaño de fuente
  • el varmatrixentorno escribe la matriz en un cuadro, por lo que debemos reiniciar el modo matemático después de configurar el tamaño y el\arraycolsep

  • Una vez terminada la caja, se utiliza en el interior \vcenterpara centrar verticalmente como las matrices habituales.

Respuesta2

Propongo combinar jugar \arraycolsep y usar una matriz de tamaño mediano (80% del tamaño del estilo de visualización), como se define en el nccmathpaquete:

    \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}

ingrese la descripción de la imagen aquí

Respuesta3

Puede insertar un espacio de 4 puntos entre columnas usando la @{}sintaxis para matrix. Además, &=no lo utilice =&para un espaciado adecuado.

ingrese la descripción de la imagen aquí

\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}

información relacionada