# [Tex/LaTex] the most elegant way to get a diagram showing elimination method to solve simultaneous equations

math-mode

First of all, I show you my effort as follows. It seems to be too complicated in coding with unsatisfied output.

\documentclass[border=12pt,12pt,varwidth]{standalone}
\usepackage{mathtools}

\begin{document}
\begin{aligned} \! \begin{aligned} 3x +2y &=7 \\ 9x +8y &=22 \end{aligned} \left| \! \begin{aligned} \times 3\\ \times 1 \end{aligned} \right| &\! \begin{aligned} 9x +6y &=21 \\ 9x +8y &=22 \end{aligned}\\ &\! \begin{aligned} -2y &=-1 \\ y &=1/2 \end{aligned} \end{aligned}
\end{document}


What I want to achieve are

• The coding must use as minimal number of keystrokes as possible.
• The output should look as follows,

where all spaces are well balanced, all equal signs are well aligned, the horizontal line exists to show the process of subtraction or addition, the sign of the process can be changed to either plus or minus, and the vertical lines are tall enough just to separate the left and right equations (no excessive vertical line).

How is the most elegant way to get such a diagram?

An elementary array implementation:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$\begin{array}{r@{}l@{\quad}l@{\quad}r@{}l@{}c} 3x + 2y & {}= 7 & \xrightarrow{\times 3} & 9x + 6y & {}= 21 \\[\jot] 9x + 8y & {}= 22 & \xrightarrow{\phantom{\times 3}} & 9x + 8y & {}= 22 & ~\smash{\raisebox{.8\normalbaselineskip}{+}} \\ \cline{4-5} & & & - 2y & {}= -1 \\[\jot] & & & y & {}= 1/2 \\ \end{array}$
\end{document}


One can play with the rule length in or to reduce the overhang on the right. For this, perhaps use \rlap{$-1$} and \rlap{1/2}.