12

Is there a package that would allow me to draw a horizontal line in math mode, like what is suggested below?

\begin{align*}
x + 2 &= 3\\ % First equation
 -2 &= -2\\  % Second equation
%% Horizontal line drawn under last equation HERE, with line as wide as 
%% first equation
x &= 1
\end{align*}
Werner
  • 603,163
user76497
  • 121

4 Answers4

18

Here's a solution that uses an array environment and takes care to preserve the appropriate amounts of spacing around operators of type mathbin ("+" and "-") and mathrel ("="). It also uses the macro \midrule (from the booktabs package) to get nice spacing around the horizontal line.

enter image description here

\documentclass{article}
\usepackage{array,amsmath,booktabs}
\begin{document}
\[
\begin{array}{ @{} r @{}>{{}}c<{{}}@{} r @{{}={}} r @{} }
x & + &  2 &  3\\
  & - &  2 & -2\\
\midrule
  &  &   x &  1\\
\end{array}
\]
\end{document}
Mico
  • 506,678
12

Easy enough: use aligned:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{aligned}
x + 2 &= 3\\ % First equation
 -2 &= -2\\  % Second equation
\hline
x &= 1
\end{aligned}
\end{equation*}
\end{document}

enter image description here

Better yet, use also booktabs and \midrule:

\documentclass{article}
\usepackage{amsmath,booktabs}
\begin{document}
\begin{equation*}
\begin{aligned}
x + 2 &= 3\\ % First equation
 -2 &= -2\\  % Second equation
\midrule
x &= 1
\end{aligned}
\end{equation*}
\end{document}

enter image description here

egreg
  • 1,121,712
6

Use a tabular

\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
 \begin{tabular}{>{$}r<{$}@{\,}>{$=}l<{$}}
x + 2 & 3  \\
   -2 & -2 \\ \hline
    x & 1
\end{tabular}
\end{document}

enter image description here

4

Here are two solutions using IEEEtrantools:

Embed IEEEeqnarraybox inside equation

\documentclass{article}

\usepackage{amsmath}
\usepackage{IEEEtrantools}

\begin{document}

\begin{equation*}
  \begin{IEEEeqnarraybox}{rCr}
              x + 2 &=&  3
    \\          - 2 &=& -2
    \\ \hline
    \\            x &=&  1  
  \end{IEEEeqnarraybox}
\end{equation*}

\end{document}

gives:

enter image description here

For a better control I recommend to use IEEEeqnarray.

Using IEEEeqnarray

\documentclass{article}

\usepackage{IEEEtrantools}
\usepackage{booktabs}

\begin{document}

\begin{IEEEeqnarray*}{rCr}
                               x + 2 &=&  3
  \\                             - 2 &=& -2
  \\*[-1.0\normalbaselineskip] \cmidrule{1-3}
  \\*[-1.5\normalbaselineskip]     x &=&  1
\end{IEEEeqnarray*}

\end{document}

gives:

enter image description here

Stefan Moser wrote an excellent tutorial on IEEEtrantools.

Adobe
  • 3,037