Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to align multiple vectors (horizontal arrays), each on a separate line. Specifically, some values are negative and some positive, and some have a decimal part and some not. I want to align everything (i.e. values 1st value of all arrays etc) at the decimal place, like this:

 ab=[-0.1  3    2.4]  
xyz=[ 3   -2.7 -2  ]  

I have almost achieved this using a single large matrix, with each row containing one vector. Aligning at the decimal point was initially manual, by breaking up each number into the integer and decimal part and putting each in a separate column, but then I found about the dcolumn package that makes it much easier.

However, since I am using one big array to ensure correct horizontal alignement across multiple lines, I cannot have a \left[ part in one column and a \right] in another. The result is that the brackets are input just by '[' and ']' and are a bit small, rather that being automatically enlarged.

I would like to know if there is any other way to force the same horizontal alignment on multiple arrays (within the same 'align' block if required) without using one big matrix. Maybe some way to nest matrices?

I have though about using tabular or tabularx for each vector and set the same column widths on all of them. While this would align the start and end of the vectors, I am 99% certain the values of each column would not be aligned.

Otherwise, some way to have a '\left[ ...\right]' block span multiple columns of an array would be usefull.

Thanks in advance

share|improve this question
add comment

2 Answers

You can nest array environments and use the dcolumn package to achieve the alignment at the decimal point. A little example:

\documentclass{article}
\usepackage{dcolumn}

\newcolumntype{R}{D{.}{.}{2,2}}

\begin{document}
\fontsize{16}{20}\selectfont
\[
\begin{array}{l@{}l@{}l}
  \begin{array}{r}
    ab=[ \\
    xyz=[
  \end{array}
  &
  \begin{array}{@{}RRR@{}}
    -2.3 & 4 & 3.56\\
    5 & -3.5 & -0.5
  \end{array}
  &
  \begin{array}{l}
    ] \\ ]
  \end{array}
\end{array}
\]

\end{document}

share|improve this answer
add comment

You can do it by hand with \phantoms or by making a tabular with a specific width

\documentclass{article}
\usepackage{mathtools,dcolumn}
\newcommand\p[1]{\phantom{#1}}
\newcommand\dnum[1]{%
    \begin{tabular}{@{}D{.}{.}{3.1}@{}}
      #1
    \end{tabular}}

\begin{document}

Do it by hand
\begin{align}
  x   &= \begin{bmatrix*}[r]     -0.1         & \p{-}3\p{.7} & \p{-}2.4\end{bmatrix*}\\
  xyz &= \begin{bmatrix*}[r] \p{-}3\p{.1} &     -2.7     &     -2\p{.4}\end{bmatrix*}
\end{align}
or inside a tabular
\begin{align}
  x   &= \begin{bmatrix*}[r] \dnum{-0.1} & \dnum{3}     & \dnum{2.4}\end{bmatrix*}\\
  xyz &= \begin{bmatrix*}[r] \dnum{3}    & \dnum{-2.7}  & \dnum{-2} \end{bmatrix*}
\end{align}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.