4

I'm kind of surprised I can't find this issue already addressed somewhere, it seems so basic: I want to typeset basic algebra solutions where you write an equation and then under it you write what you do to both sides, and then you underline that as if it's adding two things, and below that you show the result. For example, what I've been trying to write is the following,

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{alignat*}
    x & -1 = & 3\\
     & +1  & +1\\ \cline{1-3}
    &x &= 4
    \end{alignat*}
\end{document}

and most of this looks lovely except that the white space between the "+1 +1" line and the horizontal line just looks ugly. I can't use an underline because of all the alignment control. I thought of using \toprule but that doesn't seem to work in a math environment. Other ideas?

6

although i'm pretty sure this is addressed in another question, here is a suggestion.

(however, your use of alignat is missing one important thing -- the number of columns.)

all you need to do is, after the next-to-last line, just before the \cline, specify an optional negative vertical space. here i've used twice the height of a lowercase "x":

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{alignat*}{2}
    x & -1 = & 3\\
     & +1  & +1\\[-2ex] \cline{1-3}
    x & \phantom{{}-1} = & 4
    \end{alignat*}
\end{document}

output of example code

3

You probably want to use array, rather than alignat, in order to have finer control.

I propose two versions, on the left one, {+1} avoids space between the two symbols.

\documentclass{article}
\usepackage{amsmath,array,booktabs}
\begin{document}
\[
\begin{array}{
  @{}
  r % for x
  @{}
  >{{}}r % for -1 and +1
  @{}
  >{{}}c<{{}} % for the =
  @{}
  r % for the right hand side
  @{}
}
x &  -1  & = &  3\\
  & {+1} &   & +1\\
\midrule
x &    & = &  4
\end{array}
\qquad
\begin{array}{
  @{}
  r % for x
  @{}
  >{{}}r % for -1 and +1
  @{}
  >{{}}c<{{}} % for the =
  @{}
  r % for the right hand side
  @{}
}
x & -1 & = &  3\\
  & +1 &   & +1\\
\midrule
x &    & = &  4
\end{array}
\]
\end{document}

enter image description here

  • {+1} is the right way to go. (i just forgot.) but if you're going to let the rule "hang out" on the right, you should probably also have a matching projection on the left. – barbara beeton Sep 10 '14 at 21:37
  • @barbarabeeton Just forgot a trailing @{}. Thanks for noting. – egreg Sep 10 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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