Espaçamento horizontal bmatrix no ambiente de alinhamento

Espaçamento horizontal bmatrix no ambiente de alinhamento

Tenho uma matriz de blocos grande em meu documento, que viola ligeiramente a margem da página. Gostaria de reduzir o espaçamento horizontal entre os elementos da matriz de uma linha. Além disso, quero alinhar várias equações. Tentei com array e matriz mas o arraycolsepcomando não funciona como esperado.

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

insira a descrição da imagem aqui

Edição 1: esqueci de mencionar que usei uma equação bem curta na segunda linha. No entanto, a segunda linha também é muito longa e ambas não cabem em uma única linha.

Responder1

Eu definiria um varmatrixambiente onde você pode definir o \arraycolseptamanho da fonte e o tamanho da fonte.

Isto é muito mais flexível, porque você pode decidir \normalsizee reduzir a separação, mas também usar um tamanho menor.

O padrão é \smalle 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}

insira a descrição da imagem aqui

Algumas explicações.

  • A \keys_define:nnparte define uma sintaxe de valor-chave para as opções varmatrix.

    1. a sepchave define o\arraycolsep
    2. a delimchave define as cercas, use as letras padrão de amsmath, b, p, vou Vaté mesmo nada para nenhuma cerca
    3. a sizechave deve receber uma declaração de tamanho de fonte
  • o varmatrixambiente compõe a matriz em uma caixa, então precisamos reiniciar o modo matemático depois de definir o tamanho e o\arraycolsep

  • depois que a caixa é finalizada, ela é usada internamente \vcenterpara centralização vertical como matrizes usuais

Responder2

Proponho combinar o jogo \arraycolsep e o uso de uma matriz de tamanho médio (80% do tamanho do displaystyle), conforme definido no nccmathpacote:

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

insira a descrição da imagem aqui

Responder3

Você pode inserir um espaço de 4 pontos entre colunas usando a @{}sintaxe para matrix. Além disso, &=não use =&para espaçamento adequado.

insira a descrição da imagem aqui

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

informação relacionada