6

I am new to LaTex and I am trying to type a document where I show the steps I took to solve an equation however I do not know how to do this in LaTex. I am trying to display something like this:

 x^2+2x+1 = 0  
 (x+1)^2 = 0  
 x = -1

Is there a way to do this (or something similar) in LaTex? Any suggestions would be much appreciated!

ab217
  • 211

3 Answers3

13

You should consider using amsmath:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  x^2 + 2x + 1 &= 0 \\
  (x+1)^2 &= 0 \\
  \llap{$\rightarrow$\hspace{50pt}} x &= -1
\end{align*}
\end{document}
Moriambar
  • 11,466
Werner
  • 603,163
3

There is a really neat package called witharrows that does a really nice job of what you're trying to do. It creates an environment called WithArrows that takes the place of aligned. There are several tweaks you can use to adjust the spacing, color, and types of arrows used to describe the steps.

Here is an MWE:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{witharrows}

%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{equation}
\setlength{\jot}{10pt}
\begin{WithArrows}
ax^2 + bx + c & = 0 \Arrow[xoffset=-2cm]{Multiply both sides by $4a$} \\
4a^2 x^2 + 4abx + 4ac & = 0 \Arrow[xoffset=-1cm]{Subtract $4ac$} \\
4a^2 x^2 + 4abx & = - 4ac \\
4a^2 x^2 + 4abx + b^2 & = b^2 - 4ac \\
(2ax + b)^2 & = b^2 - 4ac \\
2ax + b & = \pm \sqrt{b^2 - 4ac} \\
2ax & = -b \pm \sqrt{b^2 - 4ac}
\end{WithArrows}
\nonumber
\end{equation}

\end{document}

Here is the output:

enter image description here

G. Khanna
  • 508
1

Try this:

\begin{eqnarray}
 x^2+2x+1 &=& 0      \nonumber \\
 (x+1)^2  &=& 0 \nonumber \\
  x & = & -1
\end{eqnarray}

You might want to number each step by removing the \nonumber commands; I only numbered the last one.

More examples here.

David Carlisle
  • 757,742