3

I am trying to create a system of equations with my calculation steps on the right side and a double underlined result.

I've decided to use NiceArray from the nicematrix package for the calculation steps, which has given me the intended outcome.

I guess there is a very simple way of underlining my result using nicematrixand Tikz. Unfortunately I have no experience with Tikz.

What do I have to write in order to double underline my result?

I was searching many hours for a solution to fix both of my problems (calculation steps and double underlining) and finally I think I am very close to the solution.

\documentclass{scrartcl}
\usepackage{mathtools}
\usepackage{nicematrix}

\begin{document}

\begin{equation*}
\begin{NiceArray}{RCLL}
-2x + 72 & = & 18 - 7x  &\quad | - 7x \\
-9x + 72 & = & 18 & \quad | -72 \\
-9x & = & -54  & \quad | : (-9) \\
x & = & 6
\end{NiceArray}
\end{equation*}

\end{document}

enter image description here

Karl
  • 139
  • Under which row does this double underline occur, and what is its full left/right extent? Welcome to the site. – Steven B. Segletes May 08 '19 at 17:16
  • 3
    Shhh. I won't tell anyone, but the 2nd line does not follow mathematically from the first. – Steven B. Segletes May 08 '19 at 17:17
  • I suppose adding \\\hline\hline to the end of the NiceArray is not what you are looking for? – Steven B. Segletes May 08 '19 at 17:22
  • This looks like it might be what you were looking for

    https://tex.stackexchange.com/questions/249616/tex-question-about-double-underlining-in-math-mode

    – Benjamin Compson May 08 '19 at 17:26
  • 1
    @StevenB.Segletes \\\hline\hline creates a line beneath the whole Array, which is not, what I suppose to do. @Benjamin Compson That answer creates a double underline but does not help me for my calculation steps, because I cannot use \underline for more than one column of the array. – Karl May 08 '19 at 17:32

2 Answers2

6

I'd go with array, with a special purpose command:

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{array}

\newcommand{\ssep}{\lvert\;}
\newcommand{\result}[2]{%
  \mathrlap{\underline{\underline{\mathstrut\hphantom{#1=#2}}}}%
  #1 & = & #2%
}

\begin{document}

\begin{equation*}
\setlength{\arraycolsep}{0pt}
\begin{array}{r >{{}}c<{{}} l @{\quad} l}
-2x + 72 & = & 18 + 7x  & \ssep -7x \\
-9x + 72 & = & 18       & \ssep -72 \\
-9x & = & -54           & \ssep \mathbin{:}(-9) \\
\result{x}{6} \\
\end{array}
\end{equation*}

\end{document}

enter image description here

Alternatively, with aligned:

\documentclass{scrartcl}

\usepackage{mathtools}

\newcommand{\ssep}{\lvert\;}
\newcommand{\result}[2]{%
  \mathrlap{\underline{\underline{\mathstrut\hphantom{#1=#2}}}}%
  #1 & = #2%
}

\begin{document}

\begin{equation*}
\begin{aligned}
-2x + 72 & = 18 + 7x  && \ssep -7x \\
-9x + 72 & = 18       && \ssep -72 \\
-9x      & = -54      && \ssep \mathbin{:}(-9) \\
\result{x}{6}
\end{aligned}
\end{equation*}

\end{document}

enter image description here

With a fancier highlighting:

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{hf-tikz}

\newcommand{\ssep}{\lvert\;}

\begin{document}

\begin{equation*}
\begin{aligned}
-2x + 72 & = 18 + 7x  && \ssep -7x \\
-9x + 72 & = 18       && \ssep -72 \\
-9x      & = -54      && \ssep \mathbin{:}(-9) \\
\tikzmarkin{r}x&=6\tikzmarkend{r}
\end{aligned}
\end{equation*}

\end{document}

fancier

egreg
  • 1,121,712
  • Using aligned is by far the most simple way and works perfectly for me. Thank you very much! – Karl May 08 '19 at 17:41
3

with the nicematrix package (as you intended in your minimal working example -- mwe). lines for underline results are drawn with tikz added as code-after option of NiceArray:

\documentclass{scrartcl}
\usepackage{nicematrix}

\begin{document}
    \[\setlength\arraycolsep{1.2pt}  % <--- added
\begin{NiceArray}{RCLL}%
    [code-after={\tikz\draw[double, double distance=2pt, semithick]   % <--- added 
        ([yshift=-3]4-1.south west) -- ([yshift=-3]4-3.south east);}]
-2x + 72 & = & 18 - 7x  &\quad | - 7x \\
-9x + 72 & = & 18 & \quad | -72 \\
-9x      & = & -54  & \quad | : (-9) \\
x        & = & 6
\end{NiceArray}
    \]
\end{document}

enter image description here

or fit box around result (again with use tikz as at above solution):

\documentclass{scrartcl}
\usepackage{nicematrix}

\begin{document}
    \[\setlength\arraycolsep{1.2pt}    % <--- added
\begin{NiceArray}{RCLL}%
    [code-after={\tikz\node[draw=red, semithick, fit=(4-1) (4-3)] {};}] % <--- added
-2x + 72 & = & 18 - 7x  &\quad | - 7x \\
-9x + 72 & = & 18 & \quad | -72 \\
-9x      & = & -54  & \quad | : (-9) \\
x        & = & 6
\end{NiceArray}
    \]
\end{document}

enter image description here

Zarko
  • 296,517