3

This is follow-up on the similar question. I still cannot figure out where to put ampersands on alignat environments. :(


Here is what I generated. enter image description here

To enhace the readability, I want to customize the alignment.

  • I'd like the second column to be aligned around \oplus even though it induces some spaces after the first = sign and before the second = sign.
  • Similarly, I'd like the third column to be aligned around + sign even though it induces some space after the = signs.
  • Yet, I'd like the three columns to be separated by the = signs that are vertically aligned as shown above.

How can I do that?

\documentclass{minimal}

\usepackage{amsmath,amssymb,bm}
% Matrix inverse \inv[2]{\Abf} or \inv{\Abf}
\newcommand{\inv}[2][1]{\ensuremath{{#2}^{-{#1}}}}
% Matrix transpose
\newcommand{\trans}[1]{\ensuremath{{#1}^\intercal}}

\newcommand{\Abf}{\ensuremath{\bm{A}}}
\newcommand{\Ibf}{\ensuremath{\bm{I}}}
\newcommand{\Pbf}{\ensuremath{\bm{P}}}
\newcommand{\Qbf}{\ensuremath{\bm{Q}}}
\newcommand{\Ubf}{\ensuremath{\bm{U}}}

\begin{document}

\begin{subequations}
\begin{alignat}{3}
\lambda\Ibf - \Abf
&=
\Ubf
\big(
(\lambda-n)\Ibf_{k-1}
&\oplus
\lambda\Ibf_{n-k+1}
\big)
\trans\Ubf
&=
(\lambda-n)\Pbf + \lambda\Qbf
\\
\inv{(\lambda\Ibf - \Abf)}
&=
\Ubf
\Bigg(
\frac{1}{\lambda-n}\Ibf_{k-1}
&\oplus
{\frac 1 \lambda}\Ibf_{n-k+1}
\Bigg)
\trans\Ubf
&=
{\frac 1 {(\lambda-n)}}\Pbf + {\frac 1 \lambda}\Qbf
\\
\inv[2]{(\lambda\Ibf - \Abf)}
&=
\Ubf
\Bigg(
\frac{1}{(\lambda-n)^2}\Ibf_{k-1}
&\oplus
{\frac 1 {\lambda^2}}\Ibf_{n-k+1}
\Bigg)
\trans\Ubf
&=
{\frac 1 {(\lambda-n)^2}}\Pbf + {\frac 1 {\lambda^2}}\Qbf
\end{alignat}
\end{subequations}

\end{document}

2 Answers 2

4

I have a solution where the white spaces around the \oplus and + binary operators are symmetrical:

    \documentclass{minimal}

    \usepackage{amsmath,amssymb,bm}
    % Matrix inverse \inv[2]{\Abf} or \inv{\Abf}
    \newcommand{\inv}[2][1]{\ensuremath{{#2}^{-{#1}}}}
    % Matrix transpose
    \newcommand{\trans}[1]{\ensuremath{{#1}^\intercal}}

    \newcommand{\Abf}{\ensuremath{\bm{A}}}
    \newcommand{\Ibf}{\ensuremath{\bm{I}}}
    \newcommand{\Pbf}{\ensuremath{\bm{P}}}
    \newcommand{\Qbf}{\ensuremath{\bm{Q}}}
    \newcommand{\Ubf}{\ensuremath{\bm{U}}}

    \begin{document}

    \begin{subequations}
    \begin{alignat}{4}
            \lambda\Ibf - \Abf
            &= {}&
            \Ubf
            \big(
            (\lambda-n)\Ibf_{k-1}
            &\oplus
            \lambda\Ibf_{n-k+1}
            \big)
            \trans\Ubf
            &= {} &  &
            (\lambda-n)\Pbf  & + \lambda\Qbf
    \\%%
            \inv{(\lambda\Ibf - \Abf)}
            &= {}  &
            \Ubf
            \Bigg(
            \frac{1}{\lambda-n}\Ibf_{k-1}
            &\oplus
            {\frac 1 \lambda}\Ibf_{n-k+1}
            \Bigg)
            \trans\Ubf
            &= {} &  &
            {\frac 1 {(\lambda-n)}}\Pbf  & + {\frac 1 \lambda}\Qbf
    \\%%
            \inv[2]{(\lambda\Ibf - \Abf)}
            & = &
            \Ubf
            \Bigg(
            \frac{1}{(\lambda-n)^2}\Ibf_{k-1}
            &\oplus
            {\frac 1 {\lambda^2}}\Ibf_{n-k+1}
            \Bigg)
            \trans\Ubf
            & ={} &  &
            {\frac 1 {(\lambda-n)^2}}\Pbf  & + {\frac 1 {\lambda^2}}\Qbf
    \end{alignat}
    \end{subequations}

    \end{document} 

enter image description here

0
0

Just add a && at the points where you desire the alignment:

enter image description here

Notes

  • The alignat environment produces pairs of right/l alignment, hence the need for a double && to produce left aligment (i.e., skip over the r column).
  • The minimal class should not be used for examples. There is a good question on TeX.SE, but can't find it right now so will add a link when I get back.

Code:

\documentclass{article}

\usepackage{amsmath,amssymb,bm}
% Matrix inverse \inv[2]{\Abf} or \inv{\Abf}
\newcommand{\inv}[2][1]{\ensuremath{{#2}^{-{#1}}}}
% Matrix transpose
\newcommand{\trans}[1]{\ensuremath{{#1}^\intercal}}

\newcommand{\Abf}{\ensuremath{\bm{A}}}
\newcommand{\Ibf}{\ensuremath{\bm{I}}}
\newcommand{\Pbf}{\ensuremath{\bm{P}}}
\newcommand{\Qbf}{\ensuremath{\bm{Q}}}
\newcommand{\Ubf}{\ensuremath{\bm{U}}}

\begin{document}

\begin{subequations}
\begin{alignat}{5}
\lambda\Ibf - \Abf
&=
\Ubf
\big(
(\lambda-n)\Ibf_{k-1}
&&\oplus
\lambda\Ibf_{n-k+1}
\big)
\trans\Ubf
&&=
(\lambda-n)\Pbf &&+ \lambda\Qbf
\\
\inv{(\lambda\Ibf - \Abf)}
&=
\Ubf
\Bigg(
\frac{1}{\lambda-n}\Ibf_{k-1}
&&\oplus
{\frac 1 \lambda}\Ibf_{n-k+1}
\Bigg)
\trans\Ubf
&&=
{\frac 1 {(\lambda-n)}}\Pbf &&+ {\frac 1 \lambda}\Qbf
\\
\inv[2]{(\lambda\Ibf - \Abf)}
&=
\Ubf
\Bigg(
\frac{1}{(\lambda-n)^2}\Ibf_{k-1}
&&\oplus
{\frac 1 {\lambda^2}}\Ibf_{n-k+1}
\Bigg)
\trans\Ubf
&&=
{\frac 1 {(\lambda-n)^2}}\Pbf &&+ {\frac 1 {\lambda^2}}\Qbf
\end{alignat}
\end{subequations}

\end{document}
1
  • Thanks. But what I wanted was there is no space before \oplus while there can be some space after the first = sign. How can I do that?
    – user19906
    Feb 27, 2014 at 19:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .