0

I'd like to shrink the width of the following diagonal matrix:

\begin{bmatrix}
    -V_1V_2b_{21} & & & & \\
     & -V_2V_3b_{32} & & & \\
     & & -V_1V_3b_{13} & & \\
     & & & -V_3V_4b_{34} & \\
     & & & & -V_1V_4b_{41}
\end{bmatrix}

which looks like this enter image description here

However, this matrix is taking up too much space horizontally, so is there a way for me to (easily) "shrink" it to look like below?

enter image description here

Thanks very much in advance!

2
  • use \hspace{-3em} between each column - modify dimension to suit
    – js bibra
    Commented Sep 28, 2020 at 4:28
  • Wow. That was indeed quick and easy. Thanks!
    – gouhaha
    Commented Sep 28, 2020 at 4:38

3 Answers 3

3

You can set \arraycolsep to be a negative value:

enter image description here

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\[
\begingroup
\setlength\arraycolsep{-5pt}
\begin{bmatrix}
    -V_1V_2b_{21} & & & & \\
     & -V_2V_3b_{32} & & & \\
     & & -V_1V_3b_{13} & & \\
     & & & -V_3V_4b_{34} & \\
     & & & & -V_1V_4b_{41}
\end{bmatrix}
\endgroup
\]

\end{document}

\begingroup and \endgroup are used to keep the change local.

0

https://tex.stackexchange.com/a/337013/197451

enter image description here

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\newcommand\shrink{\hspace{-3em}}
$$
\begin{bmatrix}
    -V_1V_2b_{21}\shrink & & & & \\
    & -V_2V_3b_{32}\shrink & & & \\
    & & -V_1V_3b_{13}\shrink & & \\
    & & & -V_3V_4b_{34} \shrink& \\
    & & & & -V_1V_4b_{41}
\end{bmatrix}
\quad
$$

\end{document}
0

In the following I use a single column array, with entries shifted according to a predefined factor of the widest entry, which can be chosen with an optional argument (default 0.5).

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\diagonal}{ O{0.5} m }
 {% #1 = indent factor, #2 = list of entries
  \gouhaha_diagonal:nn { #1 } { #2 }
 }

% a box for measuring the entries, a length for storing the max
\box_new:N \l__gouhaha_diagonal_box
\dim_new:N \l__gouhaha_diagonal_dim

% a sequence for storing the entries
\seq_new:N \l__gouhaha_diagonal_seq

\cs_new_protected:Nn \gouhaha_diagonal:nn
 {
  % store the entries
  \seq_set_from_clist:Nn \l__gouhaha_diagonal_seq { #2 }
  % let's get the max width
  \dim_zero:N \l__gouhaha_diagonal_dim
  \seq_map_inline:Nn \l__gouhaha_diagonal_seq
   {
    \hbox_set:Nn \l__gouhaha_diagonal_box { $##1$ }
    \dim_set:Nn \l__gouhaha_diagonal_dim
     {
      \dim_max:nn { \l__gouhaha_diagonal_dim } { \box_wd:N \l__gouhaha_diagonal_box }
     }
   }
  % now set the length to the overlap (plus the \arraycolsep)
  \dim_set:Nn \l__gouhaha_diagonal_dim { #1\l__gouhaha_diagonal_dim }
  % make the matrix
  \begin{bmatrix}
  \begin{array}{@{}l@{}}
  \seq_indexed_map_function:NN \l__gouhaha_diagonal_seq \__gouhaha_diagonal_entry:nn
  \end{array}
  \end{bmatrix}
 }

\cs_new_protected:Nn \__gouhaha_diagonal_entry:nn
 {
  \int_compare:nF { #1 = 1 } { \\ }
  \hspace{ \int_eval:n {(#1-1)}\l__gouhaha_diagonal_dim }
  #2
 }


\ExplSyntaxOff

\begin{document}

\[
\diagonal{-V_1V_2b_{21}, -V_2V_3b_{32}, -V_1V_3b_{13}, -V_3V_4b_{34}, -V_1V_4b_{41}}
\]

\[
\diagonal[0.25]{-V_1V_2b_{21}, -V_2V_3b_{32}, -V_1V_3b_{13}, -V_3V_4b_{34}, -V_1V_4b_{41}}
\]

\[
\diagonal[0.75]{-V_1V_2b_{21}, -V_2V_3b_{32}, -V_1V_3b_{13}, -V_3V_4b_{34}, -V_1V_4b_{41}}
\]

\end{document}

enter image description here

The \seq_indexed_map_function:NN function is very useful, because it provides both the loop index together with the current sequence item.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .