2

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

2
  • 1
    Unrelated: never use \text like this. Use for example _{\mathrm{...}} or use textup or textnormal instead of mathrm. The \text command does not do what you thing it does. This is a very common error.
    – daleif
    Jan 11, 2018 at 10:19
  • 1
    @daleif: Thanks for the tip, I appreciate it.
    – Freeman
    Jan 11, 2018 at 10:20

2 Answers 2

2

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}
5
  • Ah that's awesome! Why the hell was I finding that so hard. Would you mind explaining why that works?
    – Freeman
    Jan 11, 2018 at 10:22
  • plus genereally not a good idea to use _\mathrm{...}, this feature does not work in general, so better to use _{\mathrm{...}} and ones main routine.
    – daleif
    Jan 11, 2018 at 10:27
  • AndrewSwann @daleif many thanks, I really appreciate the detailed and swift assistance. I've been trying to make this work for far too long. As you can see I need to learn quite a bit even after years of using LaTeX.
    – Freeman
    Jan 11, 2018 at 10:32
  • 1
    Uh! Isn't this just align with a single & per line in front of the + sign where alignment is needed?
    – egreg
    Jan 11, 2018 at 10:34
  • @egreg Yes, but the author may need to contiunue the alignment with further equalities... Jan 11, 2018 at 10:47
2

I propose one of these three solutions. I loaded the geometry package to have more decent margins. Unrelated: the language options ofbabel` should be loaded with the document class options.

\documentclass[english]{article}
\usepackage{babel}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}

% 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{document}

\begin{equation}
% derivative
 \begin{aligned}
  \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)% \\ % R2
+\left(\Rthree{\area}\right) \\ % R3&
&+\left(\Rfivec{\area}\right) % R3
\end{aligned}
\end{equation}
\bigskip
\begin{align}
% 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)% \\ % R2
+\left(\Rthree{\area}\right) % R3&
+\left(\Rfivec{\area}\right) % R3
\notag
\end{align}
\bigskip
\begin{equation}
% derivative
 \begin{aligned}
  \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) \\ % R2
 & +\left(\Rthree{\area}\right) % R3
  +\left(\Rfivec{\area}\right) % R3
\end{aligned}
\end{equation}

\end{document} 

enter image description here

1
  • Wow! Thanks so much Bernard :) This is really helpful! Learning a lot today.
    – Freeman
    Jan 11, 2018 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .