TransWikia.com

Forcing bmatrix to have a square form: Is there a canonical way in 2020?

TeX - LaTeX Asked by Linear Christmas on June 3, 2021

Square matrices are often rendered as rectangular due to its asymmetric contents. I would like to automatically force these matrices to be square anyway using some canonical solution, i.e.,

  1. the resulting matrix ought to look nice for most purposes;
  2. is automatic (when an additional, optional argument is given for the squaring);
  3. ideally, does not require me to define new environments myself (not compulsory);
  4. has options for various xmatrix commands, e.g., x = b, B, p, or has similar syntax to xmatrix.

Here is a example picture of a non-desired outcome with bmatrix:

enter image description here

where the horisontal dimension clearly exceeds the vertical dimension.

There is an older question from 2014 whose answers do not meet some of the above criteria, either by defining new environments and probably not working for various types of xmatrix, or by being manual in essence. (The MWE in the accepted answer also does not compile).

I am willing to import any package if necessary. The solution should also work with Beamer.

  • Question: Can the above criteria (1–4) be met in at the time of writing?

Here is an MWE to play around with which was also used to generate the example image.

documentclass{beamer}

begin{document}

    begin{frame}{Example}
        %Should look like square matrix but does not.
        $$
        begin{bmatrix}
            a_{0, 0} & dots & a_{0, n - 1}  
            vdots & ddots & vdots  
            a_{n - 1, 0} & dots & a_{n - 1, n - 1}
        end{bmatrix}
        $$
    end{frame}
       
end{document}

One Answer

amsmath matrix environments use an array preamble of *{..}c you can change c to the array package wc{3em} so columns are all the same width, then adjust arraystretch to vertically stretch the matrix to match. this one is reported in the log as

(146.29016pt,131.40112pt)

so not quite square but visually the brackets looked over long if I forced the array to be even taller.

enter image description here

documentclass{beamer}
usepackage{array}

makeatletter
defenv@matrix{hskip -arraycolsep
  let@ifnextcharnew@ifnextchar
  defarraystretch{3.2}%
  array{*c@MaxMatrixCols{wc{3.4em}}}}
makeatother

begin{document}

    begin{frame}{Example}
        %Should look like square matrix but does not.
        [
        sbox0{$begin{bmatrix}
            a_{0, 0} & dots & a_{0, n - 1}  
            vdots & ddots & vdots  
            a_{n - 1, 0} & dots & a_{n - 1, n - 1}
        end{bmatrix}$}
typeout{(thewd0,thedimexprht0+dp0)}
box0
        ]
    end{frame}
       
end{document}

The sbox use in the formula is just for test measuring, not needed in real documents.

Answered by David Carlisle on June 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP