How to format a system of differential equations in latex?

Which is the best way of formatting system of differential equations ? Is there a special package maybe ? I'm actually using the environment

\begin{cases} ... \end{cases}


But I'am having trouble to align all the boundary condition to the right ? Do you have any suggestion here a sample of the code

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{physics}

\begin{document}

$$\begin{cases} \displaystyle \chi \bigg[ C_{m} \frac{\partial v}{\partial t} + I_{ion}\big( v,\mathbf{w},\mathbf{c} \big) \bigg] = \div \big( \mathbf{D_{M}} \div v \big) + I_{app} \qquad & \Omega_{0}^{s} \times \big(0,T\big]\\[20pt] \displaystyle \frac{\partial \mathbf{w}}{\partial t} = \mathbf{R}(v,\mathbf{w},\mathbf{c} \big) \qquad & \Omega_{0}^{s} \times \big(0,T\big] \\[20pt] \displaystyle \frac{\partial \mathbf{w} }{ \partial t} = \mathbf{S} \big(v,\mathbf{w},\mathbf{c} \big) \qquad & \Omega_{0}^{s} \times \big(0,T\big] \\[20pt] \displaystyle \big( \mathbf{D_M} \nabla v ) \cdot \mathbf{N_S} = 0 \qquad & \partial \Omega_{0}^{s} \times \big(0,T\big] \\[20pt] \displaystyle v = v_{0} \quad \mathbf{w} = \mathbf{w_{0}} \quad \mathbf{c} = \mathbf{c_{0}} & \partial \Omega_{0}^{s} \times \{ 0 \} \\[20pt] \end{cases}$$

\end{document}


In the picture the boundary condition are aligned on the left side instead I would like to align them on the right ( as the red line )

You might find some of the environments in mathtools useful for this. In particular, dcases is like cases, but each line is in display mode, and spreadlines changes the line spacing of aligned environments. I also used aligned, from amsmath, to add more alignment points.

I also took the liberty of defining a \vectorsym macro, for readability and so you can change the formatting of all your vectors in one place.

This MWE uses LuaLaTeX, but the body should work fine with your own preamble (You can use isomath for \vectorsym in PDFTeX, should you need to.)

i also declared some of your paired delimiters with a \DeclarePairedDelimiter command, which takes an optional size argument.

\documentclass[10pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{newcomputermodern}

\newcommand\vectorsym[1]{\symbfit{#1}}
\DeclarePairedDelimiter\closedopen{\lbrack}{\rparen}

\begin{document}

\begin{dcases} \begin{aligned} \chi \bigg[ C_{m} \frac{\partial v}{\partial t} + I_{ion}\big( v,\vectorsym{w},\vectorsym{c} \big) \bigg] &= \nabla \big( \vectorsym{D_{M}} \nabla v \big) + I_{app} \qquad &\Omega_{0}^{s} &\times \closedopen[\big]{0,T} \\ \frac{\partial \vectorsym{w}}{\partial t} &= \vectorsym{R}(v,\vectorsym{w},\vectorsym{c} \big) \qquad &\Omega_{0}^{s} &\times \closedopen[\big]{0,T} \\ \frac{\partial \vectorsym{w} }{ \partial t} &= \vectorsym{S} \big(v,\vectorsym{w},\vectorsym{c} \big) \qquad &\Omega_{0}^{s} &\times \closedopen[\big]{0,T} \\ \big( \vectorsym{D_M} \nabla v ) \cdot \vectorsym{N_S} &= 0 \qquad &\partial \Omega_{0}^{s} &\times \closedopen[\big]{0,T} \\ v = v_{0} \quad \vectorsym{w} = \vectorsym{w_{0}} \quad \vectorsym{c} &= \vectorsym{c_{0}} &\partial \Omega_{0}^{s} &\times \{ 0 \} \end{aligned} \end{dcases}

\end{document}


Also, physics (which I’m not too familiar with) seems to redefine \div to mean \nabla\cdot, but in standard LaTeX, that means ÷. I’m editing now because that tripped me up, and I’d recommend you not use ambiguous code like this.

• There's no need to use dcases if you use aligned inside cases (but I'd not recommend aligning the unrelated equals signs), because aligned forces display style by itself. Jan 1, 2021 at 21:08
• Yes this seems good , but there is also the possibility to label each equations ?
– RIXS
Jan 1, 2021 at 21:11
• @RIXS One way to do this would be to change to \begin{equation*} and add a \tag at te end of each sub-equation, e.g. (1a), (1b). Auto-numbering those would be more work. Jan 2, 2021 at 4:06

You need nothing really special. I'd avoid all those 20pt that are too much.

Just to avoid issuing \displaystyle each time, I used dcases from mathtools.

The physics package redefines \div (which is not a good thing); instead of loading it just for that, use a simple definition of \Div.

In order to simplify input, I defined a \pder command and also a \vect command for vectors to make the input more semantic.

The two subscripts in the first equation should be upright, because they're words rather than symbols.

The lines are equally spaced with the trick of inserting a phantom partial derivative in the last two rows (the second one smashed at the bottom). The \mystrut command is temporary, just for that equation environment.

Note that \bigg should instead be either \biggl or \biggr (left and right delimiters). I removed all \big (that should be \bigl or \bigr), because they don't seem really necessary.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath,mathtools}
\usepackage{amssymb}
\usepackage{bm}
%\usepackage{physics} % I'd recommend avoiding it

\newcommand{\pder}[2]{\frac{\partial#1}{\partial#2}} % or use diffcoeff
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\Div}{\bm{\nabla}\cdot}

\begin{document}

$$\newcommand{\mystrut}{\vphantom{\pder{}{}}} \begin{dcases} \chi \biggl( C_{m} \pder{v}{t} + I_{\mathrm{ion}}(v,\vect{w},\vect{c}) \biggr) = \Div (\vect{D_{M}} \Div v) + I_{\mathrm{app}} & \Omega_{0}^{s} \times (0,T] \\[1ex] \pder{\vect{w}}{t} = \vect{R}(v,\vect{w},\vect{c}) & \Omega_{0}^{s} \times (0,T] \\[1ex] \pder{\vect{w}}{t} = \vect{S} (v,\vect{w},\vect{c} ) & \Omega_{0}^{s} \times (0,T] \\[1ex] \mystrut (\vect{D_M} \Div v ) \cdot \vect{N_S} = 0 & \partial\Omega_{0}^{s} \times (0,T] \\[1ex] \smash[b]{\mystrut} v = v_{0} \quad \vect{w} = \vect{w_{0}} \quad \vect{c} = \vect{c_{0}} & \partial\Omega_{0}^{s} \times \{ 0 \} \end{dcases}$$

\end{document}


If you want right aligned boundary conditions, you can use alignedat:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath,mathtools}
\usepackage{amssymb}
\usepackage{bm}
%\usepackage{physics} % I'd recommend avoiding it

\newcommand{\pder}[2]{\frac{\partial#1}{\partial#2}} % or use diffcoeff
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\Div}{\bm{\nabla}\cdot}

\begin{document}

\newcommand{\mystrut}{\vphantom{\pder{}{}}} \left\lbrace \begin{alignedat}{2} &\chi \biggl( C_{m} \pder{v}{t} + I_{\mathrm{ion}}(v,\vect{w},\vect{c}) \biggr) = \Div (\vect{D_{M}} \Div v) + I_{\mathrm{app}} &\quad \Omega_{0}^{s} \times (0,T] \\[1ex] &\pder{\vect{w}}{t} = \vect{R}(v,\vect{w},\vect{c}) &\quad \Omega_{0}^{s} \times (0,T] \\[1ex] &\pder{\vect{w}}{t} = \vect{S} (v,\vect{w},\vect{c} ) &\quad \Omega_{0}^{s} \times (0,T] \\[1ex] &\mystrut (\vect{D_M} \Div v ) \cdot \vect{N_S} = 0 &\quad \Omega_{0}^{s} \times (0,T] \\[1ex] &\smash[b]{\mystrut} v = v_{0} \quad \vect{w} = \vect{w_{0}} \quad \vect{c} = \vect{c_{0}} &\quad \Omega_{0}^{s} \times \{ 0 \} \end{alignedat} \right.

\end{document}


Explanation: alignedat makes pairs of right-left aligned columns. So the equations are in the “left aligned part” of the first pair, whereas the boundary conditions are in the “right aligned part” of the second pair.

No need to employ a cases environment. I suggest you employ an alignedat environment instead.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath} % for 'alignedat' environment
\usepackage{amssymb,physics}

\begin{document}

\addtolength{\jot}{5pt} \left\{ \begin{alignedat}{2} \chi \smash[b]{ \Bigl[ C_{m} \frac{\partial v}{\partial t} + I_{\mathrm{ion}}( v,\mathbf{w},\mathbf{c}) \Bigr] } = \div ( \mathbf{D}_{\mathrm{M}} \div v ) + I_{\mathrm{app}} &\qquad&& \Omega_{0}^{s} \times (0,T]\\ \frac{\partial \mathbf{w}}{\partial t} = \mathbf{R}(v,\mathbf{w},\mathbf{c} ) &&&\Omega_{0}^{s} \times (0,T] \\ \frac{\partial \mathbf{w} }{ \partial t} = \mathbf{S} (v,\mathbf{w},\mathbf{c} ) &&& \Omega_{0}^{s} \times (0,T] \\ ( \mathbf{D}_{\mathrm{M}} \nabla v ) \cdot \mathbf{N_S} = 0 &&& \partial \Omega_{0}^{s} \times (0,T] \\ v = v_{0} \quad \mathbf{w} = \mathbf{w}_{0} \quad \mathbf{c} = \mathbf{c}_{0} &&& \partial \Omega_{0}^{s} \times \{ 0 \} \end{alignedat} \right.

\end{document}

• Right alignment? Why? Jan 1, 2021 at 21:05
• @egreg - The OP wrote that he/she wanted to "align all the boundary condition[s] to the right". I interpreted that as "right alignment". Is my interpretation faulty?
– Mico
Jan 1, 2021 at 22:40
• The boundary conditions are those on the right side (second column), as far as I can tell. Jan 1, 2021 at 22:42
• @egreg - yeah, in that case my interpretation was definitely faulty...
– Mico
Jan 1, 2021 at 22:43

Here are a few tips and tricks before my answer

• While your example is fairly minimal, I would still recommend removing packages that are not necessary for compilation. Examples: physics,babel.
• I would recommend steering clear of the package physics. It is somewhat infamous as a behemoth. It attempts to do too much, and does none of them particularly well. There are other smaller packages that produces better results.
• I recommend using the diffcoeff package as seen below.
• I also recommend using vec over mathbf, as it is much more explicit in the code what you mean. Using vec you know you are dealing with vectors when reading the code. In addition it is also much easier to change the notation to using arrows for instance.
• To my knowledge there does not exists any packages for producing system of differential equations, but an adequate output can be produced using alignedat. The package systeme can also be used, which I guess the other answer might use.
• I would strongly recommend you formating your code better. Using indents, and aligning the & and ='s in your code will make it much more readable when you come back to it after a while.

\documentclass[10pt,a4paper]{article}
\usepackage{mathtools,amssymb}
\usepackage{diffcoeff}
\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

\begin{dcases} {\begin{alignedat}{3} & \chi\biggl[C_m \diffp vt +I_{ion}(v,\vec{w},\vec{c})\biggr] = \div (\vec{D_M}\div v)+I_{app} \qquad & \Omega_0^s &\times (0,T]\\ & \diffp {\vec{w}}t = \vec{R}(v,\vec{w},\vec{c}) & \Omega_0^s & \times (0,T]\\ & \diffp {\vec{w}}t = \vec{S}(v,\vec{w},\vec{c}) & \Omega_0^s & \times (0,T]\\ &(\vec{D_M}\nabla u) \cdot \vec{N}_S = 0 & \partial \Omega_0^s & \times (0,T]\\ & v = v_0 \quad \vec{w}=\vec{w_0} \quad \vec{c}=\vec{c_0} & \partial \Omega_0^s & \times \{0\} \end{alignedat}} \end{dcases}

\end{document}