1

I have the following equation inside an aligned environment:

equation

\documentclass{article}
\usepackage{amsmath}
\newcommand{\expr}[1]{\delta\Delta\Gamma_{#1}}

\begin{document}

\begin{equation}
  \begin{aligned}
    X &= \expr{A} + \expr{BC} + \expr{D}\\
    &= \expr{A} + \expr{B} + \expr{C} + \expr{D}
  \end{aligned}
\end{equation}

\end{document}

I would like to align the first and second + signs on the first line with the first and last + signs on the second line. I have used a word processor to show you what I want:

sample

In other words, the \expr{BC} is centered. What is the best way to accomplish this?

5

No need to guess a good spacing, because TeX can do the work.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}% first solution
\usepackage{eqparbox}% second solution

%%% for the second solution
\newcommand{\same}[2]{\eqmakebox[#1][c]{$\displaystyle#2$}}
%%%

\newcommand{\expr}[1]{\delta\Delta\Gamma_{#1}}

\begin{document}

\begin{equation}
\renewcommand{\arraystretch}{1.2}
\setlength{\arraycolsep}{0pt}
\begin{array}{*{9}{ >{{}}c<{{}} }}
  X &=& \expr{A} &+& \multicolumn{3}{c}{\expr{BC}} &+& \expr{D} \\
    &=& \expr{A} &+& \expr{B} &+& \expr{C}         &+& \expr{D}
\end{array}
\end{equation}

\begin{equation}
\begin{aligned}
  X &= \expr{A} + \same{X}{\expr{BC}}           + \expr{D} \\
    &= \expr{A} + \same{X}{\expr{B} + \expr{C}} + \expr{D}
\end{aligned}
\end{equation}

\end{document}

The \same macro for the second solution takes as first argument an arbitrary string of characters that must be unique throughout the document for the particular parts you want to have the same width. In other words, if you use the same construction elsewhere, you need to pass something different from X.

enter image description here

4

With matrix or with array:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\expr}[1]{\delta\Delta\Gamma_{#1}}

\begin{document}

\begin{equation}\setlength\arraycolsep{0.5pt}
\begin{matrix}
  X & = \expr{A} + &       \expr{BC}     & + \expr{D}\\
    & = \expr{A} + & \expr{B} + \expr{C} & + \expr{D}
\end{matrix}
\end{equation}

\begin{equation}\setlength\arraycolsep{0.5pt}
  \begin{array}{crcl}
    X &= \expr{A} + &       \expr{BC}     & + \expr{D}\\
      &= \expr{A} + & \expr{B} + \expr{C} & + \expr{D}
  \end{array}
\end{equation}

\end{document}
3

A solution based on eqparbox (requires two compilations):

\documentclass{article}
\usepackage{amsmath}
\newcommand{\expr}[1]{\delta\Delta\Gamma_{#1}}
\usepackage{eqparbox}

\begin{document}

\begin{equation}
  \begin{alignedat}{3}
    X &= \expr{A} & & + \eqmakebox[E]{$\expr{BC}$} & & + \expr{D}\\
    &= \expr{A} & & + \eqmakebox[E]{$\expr{B} + \expr{C}$} & & + \expr{D}
  \end{alignedat}
\end{equation}

\end{document}

enter image description here

2

There are other very fine solutions, I just want to show an alternative, what I'm using mostly for all my equations (but not seeing very often on this site). IEEEeqnarray is an environment from the IEEEtran document class, but you can load only the macros with \usepackage{IEEEtrantools}. The equation array is a bit more complex at first, but can solve many more complicated alignment situations. That's what I like: A solution that's "fits all". Here is your example:

\documentclass{article}
\usepackage{IEEEtrantools}
\newcommand{\expr}[1]{\delta\Delta\Gamma_{#1}}

\begin{document}

\begin{IEEEeqnarray*}{rCcCcCc}
    X &=& \expr{A} &+&        \expr{BC}     &+& \expr{D} \\
      &=& \expr{A} &+& \expr{B}  + \expr{C} &+& \expr{D}
\end{IEEEeqnarray*}

\end{document}

IEEEeqnarray works by explicitly defining the used columns between alignment points. You can use r, c and l for right, center and left alignment. Their upper case versions additionally apply an operator spacing around the column. In your example every second column is an operator, thats why I'm using the upper case variant there.

IEEEeqnarray is of course a bit more verbose than e.g. align, but IMHO that pays out. You can check out the documentation at https://www.ctan.org/pkg/ieeetrantools.

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.