2

How do I align a system of linear differential equations in latex? I can use

\begin{cases}
x_1'(t) = x_1(t)-x_2(t)+2x_3(t)\\
x_2'(t) = -2x_1(t)+5x_2(t)+2x_3(t)\\
x_3'(t) = 8x_1(t)-5x_2(t)-2x_3(t)\\
\end{cases}

But I want the variables to line up better vertically with each x_i in its own column. I usually use the systeme package for this, but

\systeme{x_1'(t) = x_1(t)-x_2(t)+2x_3(t), x_2'(t) = -2x_1(t)+5x_2(t)+2x_3(t), x_3'(t) = 8x_1(t)-5x_2(t)-2x_3(t)}

gives me an error.

1
  • 2
    I don't think that systeme supports having the alignments after the equals sign. It's possible to have alignment if you are willing to have x_1(t)-x_2(t)_2x_3(t)=x_1'(t)
    – egreg
    Commented May 11, 2023 at 8:45

3 Answers 3

3

systeme is not apt to the job. You might use alignat, but it's cumbersome. I propose iEEEeqnarray.

\documentclass{article}
\usepackage{IEEEtrantools}

\begin{document}

\begin{IEEEeqnarray*}{rCrCrCr}
x_1'(t) & = &   x_1(t) & - &  x_2(t) & + & 2x_3(t) \\
x_2'(t) & = & -2x_1(t) & + & 5x_2(t) & + & 2x_3(t) \\
x_3'(t) & = &  8x_1(t) & - & 5x_2(t) & - & 2x_3(t) \\
\end{IEEEeqnarray*}

\end{document}

enter image description here

r means a right aligned column, while C denotes a centered column with appropriate spaces around the operation or relation symbol.

3

A solution is to use \syssubstitute. Below, for example A will be replaced by \mkern-22mu x_{1}'(t) and a will be replaced by x_{1}(t).

The \mkern-22mu and \mkern-7mu create a negative horizontal space.

Note the % at the end of the line to remove unwanted space.

Furthermore, \sysdelim.. is used to remove the delimiters for the second \systeme.

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{systeme}
\begin{document}
\syssubstitute{A{\mkern-22mu x_{1}'(t)}B{\mkern-22mu x_{2}'(t)}C{\mkern-22mu x_{3}'(t)}a{x_{1}(t)}b{x_{2}(t)}c{x_{3}(t)}}%
$\systeme{A=,B=,C=}\mkern-7mu \sysdelim..\systeme{a-b+2c,-2a+5b+2c,8a-5b-2c}$
\end{document}
2
  • 1
    You should put \syssubstitute after $, so the setting is local.
    – egreg
    Commented Dec 13, 2023 at 18:32
  • 1
    Thank you for this remark. If the settings provided by \syssubstitute are only desired in this one formula then it is indeed best to put \syssubstitute after $. But if more such formulas follow then, in that case, these settings would need to be repeated each time. Of course a macro can be created to simplify this. Another possibility is to place all those formulas in a group, if possible. I think that whether it is more efficient to keep these settings local or not depends on the situation. Commented Dec 13, 2023 at 18:57
2

You can structure the alignment using alignat:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\[
  \begin{cases}
    \begin{alignedat}{4}
      x_1'(t) ={} &&   x_1(t) & {}-{} &  x_2(t) & {}+{} & 2x_3(t) \\
      x_2'(t) ={} && -2x_1(t) & {}+{} & 5x_2(t) & {}+{} & 2x_3(t) \\
      x_3'(t) ={} &&  8x_1(t) & {}-{} & 5x_2(t) & {}-{} & 2x_3(t)
    \end{alignedat}
  \end{cases}
\]

\end{document}

Additions of {} ensure proper spacing around binary relations/operators.

You must log in to answer this question.

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