# How to left-align equations with text in a minipage environment next to a right-aligned figure?

I'm trying to get a system of equations next to a figure using the minipage environment. This is what I have come up with so far:

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{caption}

\begin{document}

\noindent The final method to predict the further development of COVID-19 concerns a SEIRD-model, which classifies individuals as susceptible (S), exposed (E), infectious (I), recovered (R) and dead (D). The number of people per class changes over time, according to the following differential equations: \\

\begin{minipage}{0.4\textwidth}
\begin{flalign*}
\frac{dS}{dt} = -\beta S(t)\frac{I(t)}{N(t)} &&\\
\frac{dE}{dt} = \beta S(t)\frac{I(t)}{N(t)} - k E(t)&&\\
\frac{dI}{dt} = k E(t) - (\gamma + \delta) I(t)&&\\
\frac{dR}{dt} = \gamma I(t) &&\\
\frac{dD}{dt} = \delta I(t) \\&&
\end{flalign*}
\end{minipage}%%%
\begin{minipage}{0.6\textwidth}
\includegraphics[width=60mm, height =25mm]{seird4.png}
\captionof{figure}{Visualization of the SEIRD model}
\label{fig:seird}
\end{minipage}%%%

\end{document}


I want the equations to align at the left of the page and the figure at the right of the page, in both cases exactly lined up with the textwidth. Also, I would like the figure to be centered in height, with the caption immediately underneath.

So far, I have managed to get the equations to be aligned to the left of the figure by setting every equation in a flalign environment separately. However, this produces a lot of space between the equations (which was fixed using nospaceflalign from How to remove unnecessary space after flalign* environment), and they also do not completely line up with the text. I tried to fix this using \makebox[\textwidth]{\makebox[1.1\textwidth], which managed to get the equations to line up with the text, but then the figure was positioned either too far to the right or underneath the equations.

This is the code I used for that:

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{caption}

\newenvironment{nospaceflalign*}
{\setlength{\abovedisplayskip}{0pt}\setlength{\belowdisplayskip}{0pt}%
\csname flalign*\endcsname}
{\csname endflalign*\endcsname\ignorespacesafterend}

\begin{document}

\noindent The final method to predict the further development of COVID-19 concerns a SEIRD-model, which classifies individuals as susceptible (S), exposed (E), infectious (I), recovered (R) and dead (D). The number of people per class changes over time, according to the following differential equations: \\

\makebox[\textwidth]{\makebox[1.1\textwidth]{%
\begin{minipage}{0.6\textwidth}
%\flushleft
\begin{nospaceflalign*}
\frac{dS}{dt} = -\beta S(t)\frac{I(t)}{N(t)} &&
\end{nospaceflalign*}
\begin{nospaceflalign*}
\frac{dE}{dt} = \beta S(t)\frac{I(t)}{N(t)} - k E(t)&&
\end{nospaceflalign*}
\begin{nospaceflalign*}
\frac{dI}{dt} = k E(t) - (\gamma + \delta) I(t)&&
\end{nospaceflalign*}
\begin{nospaceflalign*}
\frac{dR}{dt} = \gamma I(t) &&
\end{nospaceflalign*}
\begin{nospaceflalign*}
\frac{dD}{dt} = \delta I(t) \\&&
\end{nospaceflalign*}
\end{minipage}%%%
\columnsep
\begin{minipage}{0.5\textwidth}
\includegraphics[width=60mm, height =25mm]{seird4.png}
\captionof{figure}{Visualization of the SEIRD model}
\label{fig:seird}
\end{minipage}%%%
}}

\end{document}


Does anyone have an idea how to fix this?

• Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – BambOo May 16 '20 at 15:51
• 0.5\textwidth+0.6\textwidth>\textwidth. You should also add a \columnsep gap between the two. Also, don't put figure (even using [H]) inside a minipage. Use \captionof{figure} as in the first code fragment. – John Kormylo May 16 '20 at 15:51
• @BambOo, thanks for letting me know! I changed my question, hopefully this is what you meant – Quivils May 16 '20 at 16:39
• @JohnKormylo, I use 0.5 and 0.6 \textwidth such that the equations align with my text. Maybe there is another way to achieve this? I introduced the figure environment to see if \raggedleft worked, but it didn't. I changed it back now, thank you. Also, I am not sure what you mean with a \columnsep gap? I tried putting this between the two minipages but got an error message – Quivils May 16 '20 at 16:42

I propose one of these solutions: one using flalign* and the measuredfigure environment, from threeparttable, the other using a simple  align* environment nested in a fleqn environment defined by nccmath and the \ffigbox command from floatrow.

Unrelated: I simplified the typing of the derivatives in Leibniz' notation with the \diff command, from esdiff.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{esdiff, nccmath}
\usepackage{caption, floatrow}
\usepackage{threeparttable}

\begin{document}

\noindent The final method to predict the further development of COVID-19 concerns a SEIRD-model, which classifies individuals as susceptible (S), exposed (E), infectious (I), recovered (R) and dead (D). The number of people per class changes over time, according to the following differential equations: \\

\noindent\begin{minipage}{0.4\textwidth}
\begin{flalign*}
\diff{S}{t} & = -\beta S(t)\frac{I(t)}{N(t)} & & & &\vrule \\
\diff{E}{t} & = \beta S(t)\frac{I(t)}{N(t)} - k E(t) \\
\diff{I}{t} & = k E(t) - (\gamma + \delta) I(t) \\
\diff{R}{t} & = \gamma I(t) \\
\diff{D}{t} & = \delta I(t) \\
\end{flalign*}
\end{minipage}%%%
\begin{minipage}{0.6\textwidth}
\begin{measuredfigure}
\includegraphics[width=60mm, height =25mm]{cahierduneecoliere}
\caption{Visualization of the SEIRD model}%of{figure}
\label{fig:seird}
\end{measuredfigure}
\end{minipage}%%
\vskip 1cm
\noindent\begin{minipage}{0.4\textwidth}
\begin{fleqn}
\begin{align*}
\diff{S}{t} & = -\beta S(t)\frac{I(t)}{N(t)} && & & \\
\diff{E}{t} & = \beta S(t)\frac{I(t)}{N(t)} - k E(t)&&\\
\diff{I}{t} & = k E(t) - (\gamma + \delta) I(t)&&\\
\diff{R}{t} & = \gamma I(t) &&\\
\diff{D}{t} & = \delta I(t) \\&&
\end{align*}
\end{fleqn}
\end{minipage}%
\begin{minipage}{0.6\textwidth}
\ffigbox[\FBwidth]{\caption{Visualization of the SEIRD model}%
\label{fig:seird}}
{\includegraphics[width=60mm, height =25mm, valign=c]{cahierduneecoliere}}
\end{minipage}%%%%

\end{document}


You can keep it much simpler. I use a displaymath environment, so there will be no page break.

Inside it I use two minipages, one for the equations and one for the image. The equations just need aligned.

Quite important: add ties between the name and its symbol like in

susceptible~(S)


so the symbol will not be detached from the name at a line break. I also removed the colon, because it doesn't belong to the normal flow. Adding punctuation after the equations might be useful, but it's optional.

\documentclass{article}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{graphicx}

\begin{document}

The final method to predict the further development of COVID-19 concerns
a SEIRD-model, which classifies individuals as susceptible~(S), exposed~(E),
infectious~(I), recovered~(R) and dead~(D). The number of people per class
changes over time, according to the following differential equations
\begin{minipage}{0.6\textwidth} \qquad\displaystyle\begin{aligned} \frac{dS}{dt} &= -\beta S(t)\frac{I(t)}{N(t)} \\ \frac{dE}{dt} &= \beta S(t)\frac{I(t)}{N(t)} - k E(t) \\ \frac{dI}{dt} &= k E(t) - (\gamma + \delta) I(t) \\ \frac{dR}{dt} &= \gamma I(t) \\ \frac{dD}{dt} &= \delta I(t) \\ \end{aligned} \end{minipage} \begin{minipage}{0.4\textwidth} \includegraphics[width=\textwidth,height=2cm]{example-image} \captionof{figure}{Visualization of the SEIRD model} \label{fig:seird} \end{minipage}

\end{document}


I set both width and height for the image just to show the center alignment. One should never use both keys, otherwise.

Here's also the output you get if you change \qquad into \centering. I would not align the equations to the left margin anyway.