6

I typeset some systems of equations, and I really like the format of input (as well as the output) the systeme package provides.

Now, I wonder if there is a way to flushright also the right-hand side of the equation, without using \hphantom? In the example below, I get the result as I want in the second system, but not the first. But I do it with a \hphantom.

 \documentclass{minimal}
 \usepackage{systeme}
 \begin{document}
 \[
 \systeme{x+y=2,x-y=-2}
 \]
 \[
 \systeme{x+y=\hphantom{-}2,x-y=-2}
 \]
 \end{document}

giving

The output of the example

Update

Just in case someone wonders why on earth one would like to have the right-hand side flushright, here is an image that might explain it better. Without the right-hand side being flushright, the arrows look bad not ending at the same horizontal location.

showcase

Also, I can mention that I have read the documentation of the systeme package, and I did not find anything like this (but my french is rusty). I also browsed the source of the package, but that was too complicated for me...

mickep
  • 8,685

2 Answers2

11

The package systeme offers different alignment options for the left and the right hand sides. Default is r,l, that is, unknowns right aligned and constant terms left aligned. This can be changed using \sysalign.

\documentclass{article}
\usepackage{systeme}

\begin{document}

[ \sysalign{r,r}% default is r,l \systeme{x+y=2,x-y=-2} ]

\end{document}

enter image description here

Issue the \sysalign declaration in the preamble if you want it to hold for every system.


original answer (with older update)

It's a choice of the package to have the last column aligned left and, as far as I can see, there's no provision for changing it by setting an option.

You can change it by redefining the command \SYS@makesyspreamble@i that's responsible for setting the alignment in columns; the simplest way is to use regexpatch:

\documentclass{article}

\usepackage{systeme} \usepackage{regexpatch}

\makeatletter \xpatchcmd{\SYS@makesyspreamble@i} {$##$\hfil\null}% left alignment {\hfil$##$\null}% right alignment {}{} \makeatother

\begin{document}

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

\end{document}

enter image description here

Should you need to switch between left and right alignment, here's how to do it.

\documentclass{article}

\usepackage{systeme} \usepackage{regexpatch}

\makeatletter \xpatchcmd{\SYS@makesyspreamble@i} {$##$\hfil\null} {\span\SYSX@afterequalalignment\null} {}{} \newcommand{\SYSX@afterequalalignmentleft}{$##$\hfil}% default \newcommand{\SYSX@afterequalalignmentright}{\hfil$##$}% default \newcommand{\rightalignafterequal}{% \let\SYSX@afterequalalignment\SYSX@afterequalalignmentright } \newcommand{\leftalignafterequal}{% \let\SYSX@afterequalalignment\SYSX@afterequalalignmentleft } \leftalignafterequal % default \makeatother

\begin{document}

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

\end{document}

The \rightalignafterequal declaration obeys the usual scoping rules, so you can issue it in the preamble if you want all systems to have right alignment.

enter image description here

UPDATE

The most recent version of systeme no longer uses @ for private macros, so the patch should be modified.

\documentclass{article}

\usepackage{systeme} \usepackage{regexpatch}

\chardef\savedunderscorecatcode=\catcode\_ \catcode_=11 \xpatchcmd{\SYS_makesyspreamble_i} {$##$\hfil\null} {\span\SYSX_afterequalalignment\null} {}{} \newcommand{\SYSX_afterequalalignmentleft}{$##$\hfil}% default \newcommand{\SYSX_afterequalalignmentright}{\hfil$##$}% default \newcommand{\rightalignafterequal}{% \let\SYSX_afterequalalignment\SYSX_afterequalalignmentright } \newcommand{\leftalignafterequal}{% \let\SYSX_afterequalalignment\SYSX_afterequalalignmentleft } \leftalignafterequal % default \catcode`_=\savedunderscorecatcode

\begin{document}

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

\end{document}

egreg
  • 1,121,712
  • 1
    Wonderful! This does exactly what I want (I will wait a while before accepting the answer, since I've been told to do so). – mickep May 26 '15 at 20:20
  • Thanks for that update as well! I don't think I will need it, but maybe someone else who stumbles upon this question will. I will mark your answer as accepted, since it really solved my problem. Thanks again! – mickep May 27 '15 at 07:18
  • 1
    This does not seem to work in TeX Live 2023. – mf67 Dec 26 '23 at 00:29
  • 2
    @mf67 The package now offers the choice. I’ll update. – egreg Dec 26 '23 at 09:24
2

I am reviving this old post because systeme has changed so egreg's solution no longer has any effect, because the patched command name has changed.

To right-align the last column for systeme version 0.32, dated 2019/01/13 use:

\makeatletter
\catcode`\_11
\xpatchcmd{\SYS_makesyspreamble_i}
{$##$\hfil\null}% left alignment
{\hfil$##$\null}% right alignment
{}{}
\catcode`\_8
\makeatother

I hope egreg would be kind enough to update his solution for switching between right and left alignment (and correct my code if necessary).

stevem
  • 615
  • I've checked egreg's alignment switching code and all it needs is the line \xpatchcmd{\SYS@makesyspreamble@i} replaced by \catcode_11 \xpatchcmd{\SYS_makesyspreamble_i}. Not sure if it also should have\catcode\_8 at the end. – stevem Dec 03 '19 at 17:14