1

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}#2\end{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*}  
  • 1
    The standard pmatrix environment from amsmath does not accept an alignment specifier. If you are using pmatrix* from mathtools please say so. – campa Jul 22 at 13:42
  • @campa I'm not sure what to use as I'm just trying out untill I see it working... Any suggestions on what to use? The matrix was that enormous that I had to add the colvec as opposed to reduce its size. I'm open for any other suggestion on how to improve it – Jasper Jul 22 at 13:44
  • 1
    My point is that you write "In a \begin{pmatrix} I'd simply put a [l] to align the numbers on the left" but that's not true unless you are doing something which you are not showing. – campa Jul 22 at 13:45
  • Updated it, you were right as i was using the pmatrix* instead :) – Jasper Jul 22 at 13:48
1

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
   \if\relax\detokenize{#1}\relax\def\@tempa{.8}\else\def\@tempa{#1}\fi
   \@colvec}

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

\makeatother


\begin{document}

\colvec{1\\-2\\3412}
\qquad
\colvec[][l]{1\\-2\\3412}
\qquad
\colvec[.6]{1\\-2\\3412}
\qquad
\colvec[.6][r]{1\\-2\\3412}

\end{document}

enter image description here

| improve this answer | |
  • Thanks for the extensive answer! Is there an easy solution to solve the jump/mismatch when there is a minus sign just like in case 2? \hfill wont always do the job in that case unfortunately! – Jasper Jul 22 at 14:06
  • @Jasper I'm not sure I get it: would you like the numbers to be left-aligned and the minus sticking out farther to the left? That would be possible but is trickier... – campa Jul 22 at 14:08
  • Indeed thats exactly what id like to have, currently im using \hfill, but i hope there is a way to automate that – Jasper Jul 22 at 14:14
  • @Jasper Uhm, as I said, possible but tricky, I have no time right now, maybe tomorrow. – campa Jul 22 at 14:16
  • Thanks a lot, i appreciate the hulp thus far already :) – Jasper Jul 22 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.