# How to align multiple elements across align and its nested aligned?

How can I fix the first equation to make all the three equations align at the positions marked by & across align and its nested aligned while preserving the spacing \quad before \text in every equation?

In other words, I need the alignment at:

(1) The equation LHS,

(2) equal sign,

(3) \text{ }, and

(4) \Omega, \Gamma_l, r=l_r (while keeping them right-aligned/flushed)

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
\begin{align}
&\partial_t^\alpha T &=\left( \frac{1}{r} \partial_r T+%
\partial_r^2 T+%
\intertext{subject to}
&\begin{aligned}
\partial_{n_l} T &= \frac{e^{-2r^2}}{N_k}n_z-B_iT && \text{on}~&\Gamma_l,\\
%
\partial_{r} T &= -B_iT && \text{on}~&r=l_r,
\end{aligned}
\end{align}
\end{document}


• Excuse me. I have understood after your question and I have deleted my answer. +1. – Sebastiano Oct 23 '19 at 12:35
• @Sebastiano Thanks for your consideration anyway :) – Diaa Oct 23 '19 at 12:37
• @Sebastiano Another variant easier for me to handle: is it possible to include all the three equations in a single align environment while giving a number and a unique label to the first equation while giving another label and a number to the last two equations to be vertically centered between both of them? – Diaa Oct 23 '19 at 13:30
• I hope I understand your request correctly. You could add \notag on the equation where you don't want the number. I don't do well with English and I often help myself with pictures :-). – Sebastiano Oct 23 '19 at 15:15

The following requirements are satisfied:

1. A single align is used
2. LHS aligned
3. Equal signs aligned
4. \text{}s aligned
5. 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}


• For my opinion it is very good. :-). I always wish you the best. – Sebastiano Oct 23 '19 at 15:13
• Thanks, but may I know why you didn't use \intertext instead of putting the text in a separate row? – Diaa Oct 23 '19 at 16:24
• @Diaa -- It's perfectly fine to use \itnertext, I thought you wanted the text aligned with the equations. – AboAmmar Oct 23 '19 at 20:25

I would do that with alignat which gives full control on the alignment columns spacing, and no \intertext. The \mathrlap command from mathtools (which loadsamsmath) is useful to neutralise the aligned environment width and have a correct spacing in the lines above.

Unrelated: needless to load amsfontswhen 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}


• Thanks, but I have made my inquiry clearer in the main question body. So, I would like to have the alignment at four different elements (e.g. \text{ }). – Diaa Oct 23 '19 at 12:50
• I've posted an edit. Is it more like you want? – Bernard Oct 23 '19 at 13:14
• It is closer, but unfortunately, not all the prescribed elements are aligned. Another variant came to my mind, is it possible to include all the three equations in a single align environment while giving a number and a unique label to the first equation while giving another label and a number to the last two equations to be vertically centered between both of them? – Diaa Oct 23 '19 at 13:28
• You needto nest an aligned(at) or a split for that. Just to know: the missing alignment is in Ω with on Γₗ and on r = l_r? – Bernard Oct 23 '19 at 14:07
• in case you are asking, the answer is yes. It would be nicer to left-align "in" and "on" while right-aligning \Gamma and r=l_r. – Diaa Oct 23 '19 at 14:48