# Vertical Alignment in Array Environment

I have produced the following array

\begin{equation*}
\begin{array}{c|ccc}
\hline
{}          &  {\bf{b}}_1  &  {\bf{b}}_2   &  {\bf{b}}_3  \\
\hline
{\bf{a}}_1  &  \cos\theta  &  -\sin\theta  &  0  \\
{\bf{a}}_2  &  \sin\theta  &  \cos\theta   &  0  \\
{\bf{a}}_3  &      0       &       0       &  1  \\
\hline
\end{array}
\end{equation*}


where the output looks like

How can I vertically align the sin and cos in the second column?

• $\phantom{-}\cos\theta$. Dec 3, 2016 at 21:14

You could insert a \phantom{-} instruction immediately before \cos\theta in the second row.

Oh, and don't use \bf -- use \mathbf instead. \bf has been deprecated in LaTeX documents since 1994. It still works with the article, report, and book document classes, but it no longer works with the KOMA-script and memoir classes.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{array}{c|ccc}
\hline
&  \mathbf{b}_1  &  \mathbf{b}_2   &  \mathbf{b}_3  \\
\hline
\mathbf{a}_1  &  \cos\theta  &            -\sin\theta  &  0 \\
\mathbf{a}_2  &  \sin\theta  &  \phantom{-}\cos\theta  &  0 \\
\mathbf{a}_3  &      0       &                  0      &  1 \\
\hline
\end{array}
\end{equation*}
\end{document}


Addendum: To make the array more "beautiful" -- a criterion you've mentioned in a follow-up comment :-) -- you may want to both fine-tune the horizontal positioning of the second and third data columns and give the entire array a more "open" look, e.g., by using the line-drawing macros of the booktabs package.

\documentclass{article}
\usepackage{amsmath,booktabs}
\begin{document}
\begin{equation*}
\toprule
& \mathbf{b}_1 & \phantom{-}\mathbf{b}_2 & \mathbf{b}_3 \\
\cmidrule(l){2-4}
\mathbf{a}_1  &  \cos\theta  &            -\sin\theta & 0 \\
\mathbf{a}_2  &  \sin\theta  &  \phantom{-}\cos\theta & 0 \\
\mathbf{a}_3  &      0       &  \phantom{-}0          & 1 \\
\bottomrule
\end{array}
\end{equation*}
\end{document}

• Maybe adding \phantom{-} next to zero in the third row makes it look better. Thanks. :) Dec 3, 2016 at 21:18
• @H.R. - Probably. If you go that route, you should also prefix \phantom{-} to \mathbf{b}_2, right?
– Mico
Dec 3, 2016 at 21:20
• Yes! :) and also to the third column! :) Dec 3, 2016 at 21:20
• I feel that it just looks more beautiful! :) Dec 3, 2016 at 21:23
• @H.R. - I've posted an addendum showing further attempts at beautification. :-)
– Mico
Dec 3, 2016 at 21:28

Another option in this case is to use an r column alignment for the data and \multicolumn{1}{c}{} to center the headings and zero:

## Code:

\documentclass{article}
\usepackage{amsmath}

\newcommand*{\Mc}[1]{\multicolumn{1}{c}{#1}}%

\begin{document}
\begin{equation*}
\begin{array}{c|rrc}
\hline
&  \Mc{\mathbf{b}_1}  &  \Mc{\mathbf{b}_2}   &  \Mc{\mathbf{b}_3}  \\
\hline
\mathbf{a}_1  &  \cos\theta  & -\sin\theta  &  0 \\
\mathbf{a}_2  &  \sin\theta  &  \cos\theta  &  0 \\
\mathbf{a}_3  &    \Mc{0}     &    \Mc{0}   &  1 \\
\hline
\end{array}
\end{equation*}
\end{document}

• (+1) Thanks for the attention. :) Dec 3, 2016 at 21:25