2

Output from latex

I want to have the "Mass" and "Momentum" text part aligned to the left side of the page (where you see 'steady' and 'version' from the previous paragraph), while keeping the equations on the same line and centered. I have tried using {align}, \llap, {aligned}, {flalign}, and none have worked properly. I want to label each equation within the {subequations} command to reference them so \begin{equation} is used within each subequation.

\llap has managed to help me get the text to not interfere with the centering of the equations, but using \begin{flushleft}, \begin{flushright}, etc only give me errors. Here is my code:

\documentclass[a4paper,12pt,default,numbered,print,index]{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{graphicx} % Required for the inclusion of images
\usepackage{setspace}        % for use of \singlespacing and \doublespacing
\usepackage{pdfpages}
\usepackage{cite}
\usepackage[section]{placeins}
\usepackage{comment}
\usepackage{hyperref}
\usepackage{siunitx}
\usepackage{color}
\usepackage{ragged2e}
\usepackage{esvect}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{array}
\usepackage{soul}
\usepackage{bm}
\usepackage{url}
\usepackage{xparse}

\begin{document}

We can simplify our analysis by assuming the flow is inviscid ($\tau_{i,j}$ = 0), an ideal gas ($p = \rho RT$), and calorically perfect ($c_p$, $c_v$ = constant). Thus, for a homogeneous, steady, uniform gas flow in a straight duct without heat conduction, the linearised governing equations can be written as:

\begin{subequations}
\begin{equation}
\label{eq:linear_EOM_vector_mass}
\llap{\text{Mass}}\frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}' = 
\mathbf{0}
\end{equation}
\begin{equation}
\label{eq:linear_EOM_vector_mom}
\llap{\text{Momentum}}\frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} 
\nabla p' = \mathbf{0}
\end{equation}
\end{subequations}

\end{document}

I have also tried using \llap and adding on space myself (as seen below) but it's messy because each equation requires different spacings and it will never properly align:

\llap{\text{Momentum}\qquad\qquad\qquad\qquad\qquad\qquad\enspace}

Please let me know what to do! Thanks so much in advance.




EDIT #2: image for the two different alternatives given by helpful comments:

enter image description here

\documentclass[a4paper,12pt,default,numbered,print,index]{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{graphicx} % Required for the inclusion of images
\usepackage{setspace}        % for use of \singlespacing and \doublespacing
\usepackage{pdfpages}
\usepackage{cite}
\usepackage[section]{placeins}
\usepackage{comment}
\usepackage{hyperref}
\usepackage{siunitx}
\usepackage{color}
\usepackage{ragged2e}
\usepackage{esvect}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{array}
\usepackage{soul}
\usepackage{bm}
\usepackage{url}
\usepackage{xparse}

\begin{document}

We can simplify our analysis by assuming the flow is inviscid ($\tau_{i,j}$ = 0), an ideal gas ($p = \rho RT$), and calorically perfect ($c_p$, $c_v$ = constant). Thus, for a homogeneous, steady, uniform gas flow in a straight duct without heat conduction, the linearised governing equations can be written as:

\begin{subequations}
\begin{flalign}
&    \rlap{Mass}     &
    \frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}'
            & = \mathbf{0}  &   \label{eq:linear_EOM_vector_mass}\\
&    \rlap{Momentum} &
    \frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p'
            & = \mathbf{0}  &   \label{eq:linear_EOM_vector_mom}\\
&    \rlap{Energy}     &
    c_p\frac{\bar{D}}{Dt}(\bar{\rho}T' + \rho'\bar{T}) + \nabla \cdot     (\boldsymbol{u'}\bar{p} + \bar{\boldsymbol{u}}p')
            & = \dot{q}'\bar{\rho} + \bar{\dot{q}}\rho'   &       \label{eq:linear_EOM_vector_energy}\\
&    \rlap{Entropy}     &
    \frac{\bar{D}s'}{Dt}
            & = \frac{\dot{q}'}{\bar{\rho}\bar{T}}  &       \label{eq:linear_EOM_vector_entropy}\\
&    \rlap{Vorticity}     &            
    \frac{\bar{D}\boldsymbol{\xi}'}{Dt}
            & = \mathbf{0}  &   \label{eq:linear_EOM_vector_vorticity}           
\end{flalign}
\end{subequations}

\begin{subequations}
\begin{flalign}
 & \rlap{Mass} & & \frac{\bar{D}\rho'}{Dt} +     \bar{\rho}\nabla\cdot\boldsymbol{u}' = \mathbf{0} &     \label{eq:linear_EOM_vector_mass}\\
 & \rlap{Momentum} & & \frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}}     \nabla p' = \mathbf{0} & \label{eq:linear_EOM_vector_mom}\\
 & \rlap{Energy} & & c_p\frac{\bar{D}}{Dt}(\bar{\rho}T' + \rho'\bar{T}) +     \nabla \cdot (\boldsymbol{u'}\bar{p} +\bar{\boldsymbol{u}}p') =     \dot{q}'\bar{\rho} + \bar{\dot{q}}\rho' & \label{eq:linear_EOM_vector_energy}\\
 & \rlap{Entropy} & & \frac{\bar{D}s'}{Dt} = \frac{\dot{q}'}    {\bar{\rho}\bar{T}} & \label{eq:linear_EOM_vector_entropy}\\
 & \rlap{Vorticity} & & \frac{\bar{D}\boldsymbol{\xi}'}{Dt} = \mathbf{0} &     \label{eq:linear_EOM_vector_vorticity}    
\end{flalign}
\end{subequations}

\end{document}
jrjrjr
  • 373
  • 3
  • 12

3 Answers3

2

Like this?

enter image description here

with use of flalign:

\documentclass[a4paper,12pt,default,numbered,print,index]{article}
\usepackage{lipsum}
\usepackage{mathtools}

\begin{document}

\lipsum[11]

\begin{subequations}
\begin{flalign}
&    \text{Mass}     &
    \frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}'
            & = \mathbf{0}  &   \label{eq:linear_EOM_vector_mass}\\
&    \text{Momentum} &
    \frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p'
            & = \mathbf{0}  &   \label{eq:linear_EOM_vector_mom}
\end{flalign}
\end{subequations}

\end{document}

Note: mathtools load amsmath therefore is sufficient to load only it.

addendum: try this:

\documentclass[a4paper,12pt,default,numbered,print,index]{article}
\usepackage{lipsum}
\usepackage{mathtools}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}

\lipsum[11]

\begin{subequations}
\begin{center}
\begin{tabularx}{\linewidth}{lX}
Mass            &
\begin{equation}\label{eq:linear_EOM_vector_mass}
\frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}' = \mathbf{0} 
\end{equation}          \\
Momentum        &
\begin{equation}\label{eq:linear_EOM_vector_mom}
\frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p' = \mathbf{0}    
\end{equation}          \\
Energy          &
\begin{equation}\label{eq:linear_EOM_vector_energy}
c_p\frac{\bar{D}}{Dt}(\bar{\rho}T' + \rho'\bar{T}) + \nabla \cdot     (\boldsymbol{u'}\bar{p} + \bar{\boldsymbol{u}}p') = \dot{q}'\bar{\rho} + \bar{\dot{q}}\rho'   
\end{equation}
\end{tabularx}
\end{center}
\end{subequations}

\end{document}

enter image description here

Zarko
  • 296,517
  • Thanks, Zarko for your comment! Very close to what I want! I want the beginning of the text to start flushed left. The Momentum line seems to do it (?) but not the Mass line... – jrjrjr Aug 15 '17 at 21:08
  • Also, you removed the equation labels - how can I reference each equation individually via this method? – jrjrjr Aug 15 '17 at 21:08
  • sorry, i overlooked the desired position. now corrected. i didn't remove labels, only place them to right place. – Zarko Aug 15 '17 at 21:11
  • sorry, clearly I just breezed through your code and missed the label. Will try this now and get back to you in a minute. Thanks! – jrjrjr Aug 15 '17 at 21:12
  • Please see the edit! Worked ok when I had the two initial equations, but when I added the longer one it messed things up and none of the 5 seems correctly centered? How can this be fixed? – jrjrjr Aug 15 '17 at 21:32
  • equations are aligned at sign=. to be centered you need very different approach. i will return tomorrow to your question (if you will still look for answer). – Zarko Aug 15 '17 at 21:42
  • Yes, please. I've been trying to solve this for the last hour or two and haven't found an adequate solution. – jrjrjr Aug 15 '17 at 21:46
  • @jrjrjr, well before sleep i managed to write new solution ... see addendum. and please, if you attend to vote or even accept answer, do this tomorrow :) – Zarko Aug 15 '17 at 21:54
  • thanks for the suggestion. I appreciate the effort before sleep, unfortunately it adds a lot of unnecessary vertical space between the equations and isn't fully centered with the text before it. Thanks for your help - I can wait until tomorrow for a better solution if you think you can come up with one? – jrjrjr Aug 15 '17 at 21:57
  • For some reason, it feels like something that can be done... Ok, thanks for all your help anyway. Much appreciated! – jrjrjr Aug 15 '17 at 22:05
1

Here are three possibilities; the first two are variants based on the flalign environment, with a different positioning of the equations w.r.t.the left margin text. The third possibility paves the texts aligned w.r.t. each other, at some distance from the equations. It's based on alignat:

\documentclass[a4paper, 12pt, default, numbered, print, index]{article}
\usepackage{mathtools}

\usepackage{eqparbox} \newcommand{\eqmathbox}2[M]{\eqmakebox[#1]{$\displaystyle#2$}}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<5><6><7><8><9><10>
<10.95><12><14.4><17.28><20.74><24.88>
mathx10
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}

\begin{document}

We can simplify our analysis by assuming the flow is inviscid ($\tau_{i,j}$ = 0), an ideal gas ($p = ρRT$), and calorically perfect ($c_p$, $c_v$ = constant). Thus, for a homogeneous, steady, uniform gas flow in a straight duct without heat conduction, the linearised governing equations can be written as:

\begin{subequations}
\begin{flalign}
\label{eq:linear_EOM_vector_mass}
 & \rlap{Mass} & &\eqmathbox{\frac{\widebar{D}\rho'}{Dt} + \bar{ρ}∇ · \boldsymbol{u}' = \mathbf{0}} & \\[0.8ex]
\label{eq:linear_EOM_vector_mom}
 & \rlap{Momentum} & &\eqmathbox{\frac{\widebar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{ρ}}
∇ p' = \mathbf{0}}
\end{flalign}
\end{subequations}

\begin{subequations}
\begin{flalign}
\label{eq:linear_EOM_vector_mass}
 & \text{Mass} & & \frac{\widebar{D}\rho'}{Dt} + \bar{ρ}∇ · \boldsymbol{u}' = \mathbf{0} &\hspace{12em} \\[0.8ex]
\label{eq:linear_EOM_vector_mom}
 & \text{Momentum} & & \frac{\widebar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{ρ}}
∇ p' = \mathbf{0}&&
\end{flalign}
\end{subequations}

\begin{subequations}
\begin{alignat}{2}
\label{eq:linear_EOM_vector_mass}
 & \text{Mass} &\hspace{3em} &\frac{\widebar{D}\rho'}{Dt} + \bar{ρ}∇ · \boldsymbol{u}' = \mathbf{0} \\[0.8ex]
\label{eq:linear_EOM_vector_mom}
 & \text{Momentum} & & \frac{\widebar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{ρ}}
∇ p' = \mathbf{0}
\end{alignat}
\end{subequations}

\end{document} 

enter image description here

Edit: Here is how to adapt the first solution to the last version of the O.P.'s code (two variants):

\documentclass[a4paper,12pt,default,numbered,print,index]{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{graphicx} % Required for the inclusion of images
\usepackage{setspace} % for use of \singlespacing and \doublespacing
\usepackage{pdfpages}
\usepackage{cite}
\usepackage[section]{placeins}
\usepackage{comment}
\usepackage{siunitx}
\usepackage{color}
\usepackage{ragged2e}
\usepackage{esvect}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{array}
\usepackage{soul}
\usepackage{bm}
\usepackage{url}
\usepackage{xparse}
\usepackage{hyperref}
\newcommand{\myeqlabel}[1]{\rlap{\bfseries#1}}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$\displaystyle#2$}}

    \DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
    \DeclareFontShape{U}{mathx}{m}{n}{
    <5><6><7><8><9><10>
    <10.95><12><14.4><17.28><20.74><24.88>
    mathx10
    }{}
    \DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
    \DeclareFontSubstitution{U}{mathx}{m}{n}
    \DeclareMathAccent{\widebar}{0}{mathx}{"73}


\begin{document}

We can simplify our analysis by assuming the flow is inviscid ($\tau_{i,j} = 0$), an ideal gas ($p = \rho RT$), and calorically perfect ($c_p$, $c_v$ = constant). Thus, for a homogeneous, steady, uniform gas flow in a straight duct without heat conduction, the linearised governing equations can be written as:
\begin{subequations}
\begin{flalign}
& \myeqlabel{Mass} &&
    \eqmathbox{\frac{\widebar{D}\rho'}{Dt} + \bar{\rho}\,\nabla\cdot\boldsymbol{u}'
            = \mathbf{0}} & \label{eq:linear_EOM_vector_mass}\\
& \myeqlabel{Momentum} &&
    \eqmathbox{\frac{\widebar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p'
            = \mathbf{0}} & \label{eq:linear_EOM_vector_mom}\\
& \myeqlabel{Energy} && 
    \eqmathbox{c_p\frac{\widebar{D}}{Dt}(\bar{\rho}\,T' + \rho'\widebar{T}) + \nabla \cdot (\boldsymbol{u'}\bar{p} + \bar{\boldsymbol{u}}p')
            = \dot{q}'\bar{\rho} + \bar{\dot{q}}\rho' }& \label{eq:linear_EOM_vector_energy}\\
& \myeqlabel{Entropy} && 
    \eqmathbox{\frac{\widebar{D}s'}{Dt}
            = \frac{\dot{q}'}{\bar{\rho}\,\bar{T}}} & \label{eq:linear_EOM_vector_entropy}\\
& \myeqlabel{Vorticity} &&
    \eqmathbox{\frac{\widebar{D}\boldsymbol{\xi}'}{Dt}
            = \mathbf{0}} & \label{eq:linear_EOM_vector_vorticity}
\end{flalign}
\end{subequations}
\begin{subequations}
\begin{flalign}
& \myeqlabel{Mass} &&
    \eqmathbox{\frac{\widebar{D}\rho'}{Dt} + \bar{\rho}\,\nabla\cdot\boldsymbol{u}'
            = \mathbf{0}} & \label{eq:linear_EOM_vector_mass}\\
& \textbf{Momen\rlap{tum}} &&
    \eqmathbox{\frac{\widebar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p'
            = \mathbf{0}} & \label{eq:linear_EOM_vector_mom}\\
& \myeqlabel{Energy} &&
    \eqmathbox{c_p\frac{\widebar{D}}{Dt}(\bar{\rho}\,T' + \rho'\widebar{T}) + \nabla \cdot (\boldsymbol{u'}\bar{p} + \bar{\boldsymbol{u}}p')
            = \dot{q}'\bar{\rho} + \bar{\dot{q}}\rho' }& \label{eq:linear_EOM_vector_energy}\\
& \myeqlabel{Entropy} &&
    \eqmathbox{\frac{\widebar{D}s'}{Dt}
            = \frac{\dot{q}'}{\bar{\rho}\,\bar{T}}} & \label{eq:linear_EOM_vector_entropy}\\
& \myeqlabel{Vorticity} &&
    \eqmathbox{\frac{\widebar{D}\boldsymbol{\xi}'}{Dt}
            = \mathbf{0}} & \label{eq:linear_EOM_vector_vorticity}
\end{flalign}
\end{subequations}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Thanks for your suggestions! I have removed amsmath and changed the location of hyperref. All your suggestion are nice, however, what I want is closer to your first, but where the equations are centered (i.e. they are not flushed with eachother at the start of the equation). Thanks again for your help! – jrjrjr Aug 15 '17 at 21:35
  • Please see my edited code - would you know how to center the equations? Thanks! – jrjrjr Aug 15 '17 at 21:43
  • I've modified the code: the first possibility uses the eqparbox package. I defined an \eqmathbox command with an optional argument (a tag, M by default) ; its contents is typeset in mathmode, centred in the box, and all boxes with the same tag have the width of the largest contents. In addition, I defined an extensible \widebar command, stolen from mathabx, which looks better than bar with capital letters. – Bernard Aug 15 '17 at 22:08
  • Hi @Bernard. Thanks again for your efforts. As mentioned to Zarko a few minutes ago, my issue right now is centering the equations with respect to the text above. They are centered with respect to the box they are in, but not with the text (i.e. shifted to the right of the page a bit). If you know how to solve that, please let me know! – jrjrjr Aug 15 '17 at 22:12
  • I think replacing \text{...} with \rlap{...} does the trick: it makes the first column have 0 width. See the updated answer (I only touched upon the first solution) – Bernard Aug 15 '17 at 22:32
  • Hi! Thanks for your answer. Any chance this fix can be done on my version of the code? I have a lot of other equations in my thesis and would have to change ALL of them to adapt to the style you used in the first version. Please see my edit number 2 - the fix doesn't completely fix it on my end! – jrjrjr Aug 15 '17 at 22:50
  • I have added two different options (from your \rlap feedback and from the code you posted without using the new matheqbox) but none of them are centered... – jrjrjr Aug 15 '17 at 23:21
  • @jrjrjr: I've posted an adapted code (two variants, due to one label quite longer than the rest. I suggest you replace \textbf for the labels with a\myeqlabelcommand which does the job. This replacement can be done in a reasonable time with theSearch and Replacefunction. As to wrapping the middle column in an\eqmathboxcommand, the moving the&before=in front of\eqmathbox, either you have to be patient, ot you can do it withregular expressions`. – Bernard Aug 15 '17 at 23:22
  • I think your first option was more centered than the second. It worked :) Thanks so much for your help @Bernard. – jrjrjr Aug 15 '17 at 23:32
  • The second variant takes into account there is an optical illusion, due to the very different label lengths, even if the first solution is geometrically centred. – Bernard Aug 15 '17 at 23:44
0

You may want to use flalign. In the example I removed all unnecessary packages (add the ones you need, but take note that hyperref should be loaded last). There should be no blank line between the text and the display.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}

\begin{document}

We can simplify our analysis by assuming the flow is
inviscid ($\tau_{i,j}$ = 0), an ideal gas ($p = \rho RT$),
and calorically perfect ($c_p$, $c_v$ = constant). Thus,
for a homogeneous, steady, uniform gas flow in a straight
duct without heat conduction, the linearised governing
equations can be written as:
\begin{subequations}
\begin{flalign}
\label{eq:linear_EOM_vector_mass}
&\text{Mass}
&&\frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}' = \mathbf{0}
&
\\[1ex]
\label{eq:linear_EOM_vector_mom}
&\text{Momentum}
&&\frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p' = \mathbf{0}
&
\end{flalign}
\end{subequations}

\end{document}

enter image description here

On the other hand, I see no reason for the labels to be flush left:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{calc}

\begin{document}

We can simplify our analysis by assuming the flow is
inviscid ($\tau_{i,j}$ = 0), an ideal gas ($p = \rho RT$),
and calorically perfect ($c_p$, $c_v$ = constant). Thus,
for a homogeneous, steady, uniform gas flow in a straight
duct without heat conduction, the linearised governing
equations can be written as:
\begin{subequations}
\begin{alignat}{2}
\label{eq:linear_EOM_vector_mass}
&\makebox[0pt][r]{\makebox[\widthof{Momentum}][l]{Mass}}
&\qquad&\frac{\bar{D}\rho'}{Dt} + \bar{\rho}\nabla\cdot\boldsymbol{u}' = \mathbf{0}
\\[1ex]
\label{eq:linear_EOM_vector_mom}
&\makebox[0pt][r]{Momentum}
&\qquad&\frac{\bar{D}\mathbf{u}'}{Dt} + \frac{1}{\bar{\rho}} \nabla p' = \mathbf{0}
\end{alignat}
\end{subequations}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks for your suggestions! The reason why I want them flush is because the 3rd equation (which I have added in the new edit) is too long to allow for it not to be flushed left. I have changed the location of hyperref as per your suggestion. Would you mind explaining why you suggest this? Thanks again! :) – jrjrjr Aug 15 '17 at 21:33
  • Please see my edited code, any idea how to center the equations? Thanks – jrjrjr Aug 15 '17 at 21:47
  • I have added two different options (from your \rlap feedback and from the code you posted without using the new matheqbox) but none of them are centered... – jrjrjr Aug 15 '17 at 23:08