TransWikia.com

Align text in a new command

TeX - LaTeX Asked on August 25, 2021

So I’ve been looking to align text in a custom matrix that is already made smaller. See link below for reference.

https://tex.stackexchange.com/a/59080/220808

In a begin{pmatrix*} I’d simply put a [l] to align the numbers on the left, yet this is not that straight forward in a newcommand. Can somebody help me out?

I use this in my .sty file:

newcommand{colvec}[2][.8]{%
  scalebox{#1}{%
    renewcommand{arraystretch}{.8}%
    $begin{bmatrix}#2end{bmatrix}$%
  }
}

With in the Equation I use:

colvec[0.9]{
      -8.6831 times 10^{-2}&-2.4059 times 10^{-4}&-3.7120&1.0337 times 10^{-1}
      6.3872 times 10^{-1}&4.5360 times 10^{-3}&-2.4419 times 10^{1}&3.7390 times 10^{-1}
      -1.1624&-5.3189 times 10^{-2}&-5.8483 times 10^{1}&1.0665        
    }  

The initial matrix would be:

begin{pmatrix*}[l]
      -8.6831 times 10^{-2}&-2.4059 times 10^{-4}&-3.7120&1.0337 times 10^{-1}
      6.3872 times 10^{-1}&4.5360 times 10^{-3}&-2.4419 times 10^{1}&3.7390 times 10^{-1}
      -1.1624&-5.3189 times 10^{-2}&-5.8483 times 10^{1}&1.0665        
end{pmatrix*}  

One Answer

Assuming that you want to be able to control the alignment with a further optional argument, this is one possibility

documentclass{article}

usepackage{mathtools}

makeatletter

newcommand{colvec}[1][.8]{%
   begingroup
   ifrelaxdetokenize{#1}relaxdef@tempa{.8}elsedef@tempa{#1}fi
   @colvec}

newcommand{@colvec}[2][c]{%
   scalebox{@tempa}{%
      renewcommand{arraystretch}{.8}%
      $begin{bmatrix*}[#1]#2end{bmatrix*}$}%
      endgroup}

makeatother


begin{document}

colvec{1-23412}
qquad
colvec[][l]{1-23412}
qquad
colvec[.6]{1-23412}
qquad
colvec[.6][r]{1-23412}

end{document}

enter image description here

Correct answer by campa on August 25, 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