I know about align
and equation
environments, and tend to use them most of the time, but sometimes I like to have more flexibility within an array of equations, like better control on justification and horizontal spacing.
In that case, I use an array
environment.
The only downside of this method (that I know of) is the fixed vertical spacing, but for equation arrays wherein every line has the same height, it is usually ok.
For reference, here is my code :
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\newcommand*{\defeq}{\vcentcolon=}
\newcommand*{\diff}{\mathrm{d}}
\newcommand*{\pd}[3][]{%
\ensuremath%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}
\newcommand*{\pdc}[4][]{%
\ensuremath%
\left(\pd[#1]{#2}{#3}\right)_{\!\!#4}
}
\newcommand{\td}[3][]{%
\ensuremath%
\frac{\diff^{#1}#2}{\diff #3^{#1}}
}
\newcommand{\earray}[3][2]{%
\ensuremath%
\everymath{\displaystyle}%
\renewcommand*{\arraystretch}{#1}%
\begin{array}{#2}
#3
\end{array}
}
\begin{document}
\[
\earray{r@{\;}l@{\;}ll}{
\diff J^\pm
& \defeq \diff u\pm \frac{1}{C}\diff p
& =\left(F\pm\frac{1}{C}G\pdc{p}{e}{V}\right)\diff t
& \text{ along a path defined by } \td{\xi}{t}=\pm C,\\
\diff S
& \defeq \diff p + C^2 \diff V
& =G\pdc{p}{e}{V} \diff t
& \text{ along a path defined by } \td{\xi}{t}=0
}
\]
\begin{align*}
\diff J^\pm
& \defeq \diff u\pm \frac{1}{C}\diff p
& =\left(F\pm\frac{1}{C}G\pdc{p}{e}{V}\right)\diff t
& \text{ along a path defined by } \td{\xi}{t}=\pm C,\\
\diff S
& \defeq \diff p + C^2 \diff V
& =G\pdc{p}{e}{V} \diff t
& \text{ along a path defined by } \td{\xi}{t}=0.
\end{align*}
\end{document}
Here is what the code produces.
So, my question is : is there a way to manually add tags inside displayed math ? Alternatively, is there a better way to proceed, or a better environment, for such cases ?
Best Answer
An
alignat*
environment is more suitable here thanalign*
or anarray
(within a display-math environment). See below.For numbering lines, you can use the command
\numberthis
which I define below. That command takes one optional argument, which if not empty, is used to create a label for cross-referencing. (Thanks to wasteofspace for his/her comments.)Also, see David Carlisle's recommendation regarding the (ab)use of
\ensuremath
.