4

For example with the code below:

\begin{bmatrix}
\mathbf{P}^-_{k} & \mathbf{C}_k\\
\mathbf{C}_k & \mathbf{S}_k
\end{bmatrix}

you will get a result looking like this:

enter image description here

It is apparent that those subscripts k in the matrix are not aligned both horizontally and vertically

How to properly align those subscripts in bmatrix environment?

Or are there any other matrix environments could cope with this well?

  • For the vertical alignment of the subscripts, add ^{} to the entries that have no superscript. About the horizontal alignment, I'm not seeing it's necessary, as all the terms have different widths.. – egreg Jun 6 at 13:47
5

To align the 4 terms on their subscripts, I suggest you combine a bmatrix*[r] environment (provided by the mathtools package) with a \mathrlap{-} instruction (also provided by the mathtools package).

Update: to perform vertical alignment of the k subscripts in the first row, I suggest you provide add a \vphantom{-} superscript term to \mathbf{C}_k term in the upper-right cell.

The result of the adjustments is shown in the lower matrix:

enter image description here

\documentclass{article}
\usepackage{mathtools} % for bmatrix* env. and \mathrlap macro
\begin{document}
\[
\begin{bmatrix}
\mathbf{P}^{-}_{k} & \mathbf{C}_k \\
\mathbf{C}_k       & \mathbf{S}_k
\end{bmatrix}
\]

\[
\begin{bmatrix*}[r]
\mathbf{P}^{\mathrlap{-}}_{k} & \mathbf{C}^{\vphantom{-}}_k \\
\mathbf{C}_k                  & \mathbf{S}_k
\end{bmatrix*}
\]
\end{document}
  • Thank you, but it seems that they only align in vertical direction? – Nathan Explosion Jun 6 at 13:09
  • @NathanExplosion - Please see my updated answer. – Mico Jun 6 at 13:15
4

Here are two possibilities:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\[
  \begin{bmatrix}
    \mathbf{P}^{-}_{k} & \mathbf{C}^{\vphantom{-}}_k\\
    \mathbf{C}_k & \mathbf{S}_k
  \end{bmatrix}
  \begin{bmatrix}
    \mathbf{P}_{k}\llap{${}^{-}\mkern -3mu$} & \mathbf{C}_k\\
    \mathbf{C}_k & \mathbf{S}_k
  \end{bmatrix}
\]
\end{document}

Screenshot

Note: the second method uses manual adjustment for the horizontal position of the minus exponent (see the \mkern -3mu).

  • Two flaws in the update: The minus isn't at the same vertical position, and in the second column, the subscripts aren't at the same horizontal position. – barbara beeton Jun 6 at 13:58
  • @barbarabeeton I've fixed the first matrix, thanks. Concerning your remark on the minus sign, the two matrices are independent solutions, so I don't understand really the problem: I consider that it is an editorial choice to make: either you keep the minus superscript in its normal place and adjust the (1,2) matrix element to behave as if it had an invisible similar superscript (first solution), or you write the (1,1) element as if it had no superscript and manually add the minus in superscript position in a way that doesn't push the subscript downward (second solution). – frougon Jun 6 at 14:15
  • @barbarabeeton: My answer only adresses alignment of the subscripts on a horizontal line because it was written before the OP modified its question to add “both horizontally and vertically.” (and I consider it a bit extreme to ask for alignment of subscripts on a vertical line: if you align the k's, then something else is necessarily going to be “wrong”: either the spacing between C or S and k, or the alignment of S and C on a vertical line) – frougon Jun 6 at 14:18
  • @frougon@barbarabeeton yes, I've edited the question, sorry for the confusion. – Nathan Explosion Jun 7 at 7:23
  • @frougon My congratulations for the first gold medal. – Sebastiano Jun 20 at 21:52

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.