4

This question already has an answer here:

I would like to write an environment to write linear system of equations that could be used with

\begin{linearSystem}
2x&+y&=&2\\
x&-3y&=&1
\end {linearSystem}

and should display

2x +y=2
 x-3y=1

Every piece of equation should be aligned on the right and no spacing should be added.

I have tried to use the aligned environment with

\[\left\{\begin{aligned}[c]
2x&+y&=&2\\
x&-3y&=&1
\end{aligned}\right.\]

But I get something like

2x+y  =2
 x-3y =1

which is not what I want. Is there a way to have an "aligned" environment that justifies everything on the right and that does not introduce any spacing every 2 "pieces" of equation.

marked as duplicate by Werner align Jul 22 at 16:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Did you tried \hfill? like the below code \begin{eqnarray*} \hfill 2x+y=2\\ \hfill 3y=1 \end {eqnarray*} – TVM Boy Jul 22 at 13:02
  • @TVM Boy: I would like the environment to work without using any \hfill. Moreover, it won't remove the extra space that is added by the aligned environment. – InsideLoop Jul 22 at 13:06
5

It is already possible with the systeme package. Why reinvent the wheel?

\documentclass{article}
\usepackage{systeme}

\begin{document}

 \[ \systeme{2x + y = 2, x-3y= 1} \]

\end{document} 

enter image description here

4

I'm using instead of systeme package (it was my first thought - the same thought of @Bernard 😊) spalign package that it works, if we use the correct syntax, the same. It is very important that the blank spaces into \spalignsys should not be removed otherwise there is no alignment of the variables.

enter image description here

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

\begin{document}
\[ 
\spalignsys{2x + y = 2; x - 3y = 1}
\]
\end{document}
  • 1
    You've made me discover this package (+1). Thanks! – Bernard Jul 22 at 15:25
  • @Bernard Aahahaha :-) also Zarko has written the similar your comment. – Sebastiano Jul 22 at 15:27
2

Here is an environment for linear systems. It's not exactly what you describe because, it is designed to align also the signs. It's more difficult to use (more &) but I think that the result is better.

 \documentclass{article}

 \usepackage{amsmath}
 \usepackage{xparse}


 \ExplSyntaxOn
 \makeatletter

 \cs_new_protected:Nn \__insideloop_system_cr:
   {
     \scan_stop:
     \group_align_safe_begin:
     \peek_meaning_remove:NTF * \__insideloop_system_cr_i: \__insideloop_system_cr_i:
   }
 \cs_new_protected:Nn \__insideloop_system_cr_i:
   {
     \peek_meaning:NTF [ % ]
       \__insideloop_system_cr_ii:
       { \__insideloop_system_cr_ii: [ \c_zero_dim ] }
   }
 \cs_new_protected:Npn \__insideloop_system_cr_ii: [ #1 ]
   {
     \group_align_safe_end:
     \cr
     \noalign { \skip_vertical:n { #1 } \scan_stop: }
   }
 \NewDocumentEnvironment { system } { }
   {
     \group_begin:
     \cs_set_eq:NN \\ \__insideloop_system_cr:
     \left \{ \null \,
     \vcenter
     \bgroup \spread@equation
     \ialign
       \bgroup
          \strut \hfil $##$ & $##$ \hfil && \enspace $##$ \enspace &
          \hfil $##$ & $##$ \hfil \crcr
   }
   {      \crcr
       \egroup
     \egroup
     \right.
     \group_end:
   }

 \makeatother
 \ExplSyntaxOff



 \begin{document}


 $\begin{system}
 3 & x & + & 4 & y & + & 5 & z & = & 0 \\
 & x & - & 2 & y & - & & z & = & 7 \\
 -7 & x & + & 3 & y & + & 9 & z & = & 12
 \end{system}$

 \end{document}

Result of the code above

Not the answer you're looking for? Browse other questions tagged or ask your own question.