4

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

enter image description here

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

1
  • $\phantom{-}\cos\theta$. – Bernard Dec 3 '16 at 21:14
4

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.

enter image description here

\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.

enter image description here

\documentclass{article}
\usepackage{amsmath,booktabs}
\begin{document}
\begin{equation*}
\begin{array}{@{}ccc@{\qquad}c@{}}
\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}
6
  • Maybe adding \phantom{-} next to zero in the third row makes it look better. Thanks. :) – Hosein Rahnama Dec 3 '16 at 21:18
  • @H.R. - Probably. If you go that route, you should also prefix \phantom{-} to \mathbf{b}_2, right? – Mico Dec 3 '16 at 21:20
  • Yes! :) and also to the third column! :) – Hosein Rahnama Dec 3 '16 at 21:20
  • I feel that it just looks more beautiful! :) – Hosein Rahnama Dec 3 '16 at 21:23
  • @H.R. - I've posted an addendum showing further attempts at beautification. :-) – Mico Dec 3 '16 at 21:28
4

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:

enter image description here

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
  • (+1) Thanks for the attention. :) – Hosein Rahnama Dec 3 '16 at 21:25

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.