How to align multiple elements across align and its nested aligned?
The following requirements are satisfied:
- A single
align
is used - LHS aligned
- Equal signs aligned
\text{}
s aligned- Giving a number and a unique label to the first equation while giving another label and a number to the last two equations that is vertically centered between both of them.
You can go further and right-align \Omega
, \Gamma_l
, r=l_r
, but I considered it ugly and decided not to do it.
\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\begin{document}
\begin{align}
\partial_t^\alpha T &= \left(\frac{1}{r} \partial_r T+\partial_r^2 T+\partial_z^2 T \right) & \hspace{-9ex} & \text{in~ } \Omega \label{eq:first} \\
\makebox[0pt]{subject to} & & \hspace{-9ex} & \notag \\
\partial_{n_l} T &= \frac{e^{-2r^2}}{N_k}n_z-B_iT & \hspace{-9ex} & \text{on~ } \Gamma_l, \notag \\[-\normalbaselineskip]
& & \hspace{-9ex} & \label{eq:lasttwo} \\
\partial_r T &= -B_iT & \hspace{-9ex} & \text{on~ } r=l_r,\notag
\end{align}
\end{document}
I would do that with alignat
which gives full control on the alignment columns spacing, and no \intertext
. The \mathrlap
command from mathtools (which loads
amsmath`) is useful to neutralise the aligned environment width and have a correct spacing in the lines above.
Unrelated: needless to load amsfonts
when you load amssymb
.
\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{optidef}
\begin{document}
\begin{alignat}{3}
&\partial_t^\alpha T & &=\left( \frac{1}{r}\, \partial_r T+%
\partial_r^2 T+%
\partial_z^2 T \right) &\quad &\text{in}~\Omega \\
%\intertext[0ex]{subject to}
\text{subject to} & \notag \\[-2ex]
&\mathrlap{\begin{alignedat}{2}
\partial_{n_l} T &= \frac{e^{-2r^2}}{N_k}n_z-B_iT &\quad \text{on}~&\Gamma_l, \\
%
\partial_{r} T &= -B_iT
& \text{on}~&r=l_r,
\end{alignedat}}
\end{alignat}
\end{document}
Edit: a variant:
\begin{alignat}{4}
& & \qquad&\partial_t^\alpha T & &=\left( \frac{1}{r}\, \partial_r T+%
\partial_r^2 T+%
\partial_z^2 T \right) &\quad &\text{in}~\Omega \\
%\intertext[0ex]{subject to}
& \text{subject to} & & \notag \\[-2ex]
& & &\mkern-3.6mu\mathrlap{\begin{alignedat}{2}
\partial_{n_l} T &= \frac{e^{-2r^2}}{N_k}n_z-B_iT &\quad \text{on}~&\Gamma_l, \\
%
\partial_{r} T &= -B_iT
& \text{on}~&r=l_r,
\end{alignedat}}
\end{alignat}