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.,
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
:
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.
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}
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.
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP