[Tex/LaTex] How to flush left alignments using alignat

alignalignatvertical alignment

Could anyone help me align this multiline equation correctly? I am having very little luck. It is too long for one line, so I have spread it over 4 lines. I am trying to get all the +(#) terms after '\chemspec_\text{vit}' to be aligned to the left to remove the white space between the equations (so all the plus signs sit underneath each other).

\documentclass{article}
\usepackage[english]{babel} 
\usepackage{amsmath}

\begin{document}

% commands
\newcommand{\dydx}[2]{\frac{\text{d}#1}{\text{d}#2}}
\newcommand{\pRPEc}[1]{p_\text{RPE}^{(#1)}}
\newcommand{\pILMc}[1]{p_\text{ILM}^{(#1)}}
\newcommand{\kelc}[1]{k_\text{el}^{(#1)}}
\newcommand{\Sret}{S_\text{ret}}
\newcommand{\Vvit}{V_\text{vit}}
\newcommand{\SVit}{\frac{\Sret}{\Vvit}}
\newcommand{\konv}{k_\text{on}^{(v)}}
\newcommand{\koffv}{k_\text{off}^{(v)}}
\newcommand{\KDv}{K_\text{D}^{(v)}}
\newcommand{\konn}{k_\text{on}^{(n)}}
\newcommand{\koffn}{k_\text{off}^{(n)}}
\newcommand{\chemspec}{\R}
\newcommand{\area}{\text{ret}}
\newcommand{\V}{v}
\newcommand{\R}{r}
\newcommand{\VR}{c}
\newcommand{\RVR}{h}
\newcommand{\N}{n}
\newcommand{\RN}{m}
\newcommand{\VRN}{f}
\newcommand{\RVRN}{\left(n_0-\left\{\N+\RN+\VRN\right\}\right)}
\newcommand{\Rone}[1]  {\koffv \VR_#1 - 2\konv\V_#1\R_#1}   % R1
\newcommand{\Rtwo}[1]  {2\koffv \RVR_#1 - \konv\R_#1\VR_#1} % R2
\newcommand{\Rthree}[1]{\koffn \RN - \konn\R_#1\N}          % R3
\newcommand{\Rfivec}[1]{\koffv \RVRN - \konv\R_#1\VRN}      % R5c

\begin{alignat}{2}
% derivative
\dydx{\chemspec_\area}{t} &= 
% transfer
 \left(\SVit\right)\pILMc{\chemspec}\chemspec_\text{ret}                                % ret --> vit
-\left[\left(\SVit\right)\pILMc{\chemspec}+\kelc{\chemspec}\right]\chemspec_\text{vit}  % vit --> ret
% reactions
 &+\left(\Rone{\area}\right)\\              %  R1
&&+\left(\Rtwo{\area}\right)\nonumber\\     %  R2
&&+\left(\Rthree{\area}\right)\nonumber\\   %  R3
&&+\left(\Rfivec{\area}\right)\nonumber     %  R5c
\end{alignat}

\end{document}

enter image description here

EDIT: I explained that poorly, this is what I'm trying to achieve:

enter image description here

Best Answer

Just add one extra & to each of these lines:

Sample output

\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath,geometry}

\begin{document}

% commands
\newcommand{\dydx}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}
\newcommand{\pRPEc}[1]{p_{\mathrm{RPE}}^{(#1)}}
\newcommand{\pILMc}[1]{p_{\mathrm{ILM}}^{(#1)}}
\newcommand{\kelc}[1]{k_{\mathrm{el}}^{(#1)}}
\newcommand{\Sret}{S_{\mathrm{ret}}}
\newcommand{\Vvit}{V_{\mathrm{vit}}}
\newcommand{\SVit}{\frac{\Sret}{\Vvit}}
\newcommand{\konv}{k_{\mathrm{on}}^{(v)}}
\newcommand{\koffv}{k_{\mathrm{off}}^{(v)}}
\newcommand{\KDv}{K_{\mathrm{D}}^{(v)}}
\newcommand{\konn}{k_{\mathrm{on}}^{(n)}}
\newcommand{\koffn}{k_{\mathrm{off}}^{(n)}}
\newcommand{\chemspec}{\R}
\newcommand{\area}{\mathrm{ret}}
\newcommand{\V}{v}
\newcommand{\R}{r}
\newcommand{\VR}{c}
\newcommand{\RVR}{h}
\newcommand{\N}{n}
\newcommand{\RN}{m}
\newcommand{\VRN}{f}
\newcommand{\RVRN}{\bigl(n_0-\bigl\{\N+\RN+\VRN\bigr\}\bigr)}
\newcommand{\Rone}[1]  {\koffv \VR_#1 - 2\konv\V_#1\R_#1}   % R1
\newcommand{\Rtwo}[1]  {2\koffv \RVR_#1 - \konv\R_#1\VR_#1} % R2
\newcommand{\Rthree}[1]{\koffn \RN - \konn\R_#1\N}          % R3
\newcommand{\Rfivec}[1]{\koffv \RVRN - \konv\R_#1\VRN}      % R5c

\begin{alignat}{2}
% derivative
\dydx{\chemspec_\area}{t} &=
% transfer
 \Bigl(\SVit\Bigr)\pILMc{\chemspec}\chemspec_{\mathrm{ret}}                                % ret --> vit
-\Bigl[\Bigl(\SVit\Bigr)\pILMc{\chemspec}+\kelc{\chemspec}\Bigr]\chemspec_{\mathrm{vit}}  % vit --> ret
% reactions
 &&+\bigl(\Rone{\area}\bigr)\\              %  R1
&&&+\bigl(\Rtwo{\area}\bigr)\nonumber\\     %  R2
&&&+\bigl(\Rthree{\area}\bigr)\nonumber\\   %  R3
&&&+\bigl(\Rfivec{\area}\bigr)\nonumber     %  R3
\end{alignat}

\end{document}

The alignment of elements in alignat is

right & left & right & left & right & left ...

Other changes:

  • add geometry package to get your page width
  • used \mathrm instead of \text for consistent typesetting (\text changes with the surrounding formatting)
  • replaced \left...\right by specific sizing commands, \left...\right are often too big

You could instead consider using an aligned (e.g. as \begin{aligned}[t]) for the last block. That will make it easier to move to a new line if needed. E.g.

Second sample

\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath,geometry}

\begin{document}

% commands
\newcommand{\dydx}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}
\newcommand{\pRPEc}[1]{p_{\mathrm{RPE}}^{(#1)}}
\newcommand{\pILMc}[1]{p_{\mathrm{ILM}}^{(#1)}}
\newcommand{\kelc}[1]{k_{\mathrm{el}}^{(#1)}}
\newcommand{\Sret}{S_{\mathrm{ret}}}
\newcommand{\Vvit}{V_{\mathrm{vit}}}
\newcommand{\SVit}{\frac{\Sret}{\Vvit}}
\newcommand{\konv}{k_{\mathrm{on}}^{(v)}}
\newcommand{\koffv}{k_{\mathrm{off}}^{(v)}}
\newcommand{\KDv}{K_{\mathrm{D}}^{(v)}}
\newcommand{\konn}{k_{\mathrm{on}}^{(n)}}
\newcommand{\koffn}{k_{\mathrm{off}}^{(n)}}
\newcommand{\chemspec}{\R}
\newcommand{\area}{\mathrm{ret}}
\newcommand{\V}{v}
\newcommand{\R}{r}
\newcommand{\VR}{c}
\newcommand{\RVR}{h}
\newcommand{\N}{n}
\newcommand{\RN}{m}
\newcommand{\VRN}{f}
\newcommand{\RVRN}{\bigl(n_0-\bigl\{\N+\RN+\VRN\bigr\}\bigr)}
\newcommand{\Rone}[1]  {\koffv \VR_#1 - 2\konv\V_#1\R_#1}   % R1
\newcommand{\Rtwo}[1]  {2\koffv \RVR_#1 - \konv\R_#1\VR_#1} % R2
\newcommand{\Rthree}[1]{\koffn \RN - \konn\R_#1\N}          % R3
\newcommand{\Rfivec}[1]{\koffv \RVRN - \konv\R_#1\VRN}      % R5c

\begin{align}
  \dydx{\chemspec_\area}{t}
  &= \Bigl(\SVit\Bigr)\pILMc{\chemspec}\chemspec_{\mathrm{ret}}
    -\Bigl[\Bigl(\SVit\Bigr)\pILMc{\chemspec}+\kelc{\chemspec}\Bigr]
    \chemspec_{\mathrm{vit}}
    \begin{aligned}[t]
      &+\bigl(\Rone{\area}\bigr)\\
      &+\bigl(\Rtwo{\area}\bigr)\\
      &+\bigl(\Rthree{\area}\bigr)\\
      &+\bigl(\Rfivec{\area}\bigr)
    \end{aligned}
  \\
  &= \Bigl(\SVit\Bigr)\pILMc{\chemspec}\chemspec_{\mathrm{ret}}
    -\Bigl[\Bigl(\SVit\Bigr)\pILMc{\chemspec}+\kelc{\chemspec}\Bigr]
    \chemspec_{\mathrm{vit}}
  \\
  &\qquad
    \begin{aligned}[t]
      &+\bigl(\Rone{\area}\bigr)\\
      &+\bigl(\Rtwo{\area}\bigr)\\
      &+\bigl(\Rthree{\area}\bigr)\\
      &+\bigl(\Rfivec{\area}\bigr)
    \end{aligned}
        \nonumber
\end{align}

\end{document}
Related Question