2

So I got help for my LaTeX problem. I am in need of a little more help to get this example to look perfect. I want to perfectly align everything in the words section of each of my equations. I would be happy to get some assistance. Here's the code to the part I need help with:

\section{Applying the Steps}

\noindent {\bf Example:} Simplify \(x+3-2x+(4+2)^2+3x\)

\begin{multialign} 

\item

& x+3+(4+2)^2+3x  &&   \\

& = x+3x+3+(4+2)^2 & \text{Rearrange the terms}

&& \\

& = 4x + 3 + (4+2)^2 & \text{Addition(for $x$)}

&& \\

& = 4x + 3 + (6)^2 & \text{Parentheses}

&& \\

& = 4x + 3 + 36 & \text{Exponent}

&& \\

& = 4x + 39 & \text{Addition} &&

\end{multialign}

\noindent {\bf Example:} Simplify \(3x-5(4+3)^2-3x+8x\)

\begin{multialign}

\item \nonumber

& 3x-5(4+3)^2-3x+8x &&  \\

&= 3x-3x+8x-5(4+3)^2 & \text{Rearrange the terms}

&& \\

&= 0+8x-5(4+3)^2 & \text{Subtraction (for $x$)} 

&& \\

&= 8x - 5(4+3)^2 & 

\text{Addition (for $x$)}

&& \\

& = 8x - 5(7)^2 & \text{Parentheses}

&& \\

& = 8x - 5(49) & \text{Exponent}

&& \\

& = 8x - 245 & \text{Multiplication} && \\

\end{multialign}

Here's a picture of how the portion I need help with looks like. enter image description here

mvkorpel
  • 1,598
Gamerdue
  • 183
  • 1
    I've taken the liberty of indenting all lines of LaTeX code contained in your posting by four spaces. This may be done easily, by the way, by highlighting the lines in question and clicking on the {} "button" in the row above the editing window. Please consider editing your code further to make it into an MWE (which should start with \documentclass{...} and ends with \end{document}) that gives rise to the screenshot you've posted. – Mico Jul 15 '14 at 04:22
  • 1
    It's not clear what you need help aligning. The example looks fine to me. I haven't heard of multialign before; please include (as Mico has said) a complete example that compiles correctly. – Will Robertson Jul 15 '14 at 04:32
  • 2
    @WillRobertson - The multialign environment is due to egreg, provided in a solution he created for an earlier question by the OP. At any rate, the OP should provide an MWE rather than make readers play detective to find the definition of multialign. – Mico Jul 15 '14 at 04:47
  • No like I got the multi align thing down. except that the alignment of my lines are not perfectly aligned yet. In addition, I don't know how to make those numbers disappear underneath the examples. – Gamerdue Jul 15 '14 at 17:20

2 Answers2

4

Assuming you want to use the multialign environment that was defined by @egreg in an answer to your posting How to Align systems, all you need to do is to rearrange some of the & alignment symbols. Observe that one must not have all-blank lines in an align environment (or one, such as multialign, that's derived from align and friends). Separately, I would recommend indenting the second and subsequent lines of the derivation relative to the first line.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcounter{multialign}
\makeatletter
%% see https://tex.stackexchange.com/a/191379/5001 for the original definition of multialign
\newenvironment{multialign} 
  {%%\setcounter{multialign}{0}%
   \def\item{\refstepcounter{multialign}\themultialign.\qquad}%
   \start@align\tw@\st@rredtrue\m@ne}
  {\endalign}
\makeatother
\allowdisplaybreaks
\begin{document}
\section{Applying the Steps}

\textbf{Example:} Simplify \(x+3-2x+(4+2)^2+3x\)
\begin{multialign} 
\item
x&+3+(4+2)^2+3x    &&&\\ 
& = x+3x+3+(4+2)^2 && \text{Rearrange the terms}\\
& = 4x + 3 + (4+2)^2 && \text{Addition (for $x$)}\\
& = 4x + 3 + (6)^2 && \text{Parentheses}\\
& = 4x + 3 + 36 && \text{Squaring}\\
& = 4x + 39 && \text{Addition}
\end{multialign}

\noindent \textbf{Example:} Simplify \(3x-5(4+3)^2-3x+8x\)
\begin{multialign}
\item
3x&-5(4+3)^2-3x+8x &&&\\
&= 3x-3x+8x-5(4+3)^2 && \text{Rearrange the terms}\\
&= 0+8x-5(4+3)^2 && \text{Subtraction (for $x$)} \\
&= 8x - 5(4+3)^2 && \text{Addition (for $x$)}\\
& = 8x - 5(7)^2 && \text{Parentheses}\\
& = 8x - 5(49) && \text{Squaring}\\
& = 8x - 245 && \text{Multiplication} \\
\end{multialign}

\end{document}
Mico
  • 506,678
  • this would look nicer if all the - signs were aligned -- and i don't think it's necessary to align them with the plus or minus in the first line. a \quad beyond the beginning of the first line would probably be a good amount of spacing. (actually, that's what i was trying to suggest to @egreg in my comment on his answer in the earlier posting.) there is undoubtedly a "clean" way to do this, but i haven't come up with one yet. – barbara beeton Jul 15 '14 at 13:11
  • Hey Mico, how do I get rid of the numbering problems under the word example based on your codes? – Gamerdue Jul 15 '14 at 17:24
  • @Gamerdue - You could leave off the \item directive. – Mico Jul 15 '14 at 18:40
4

shamelessly stealing the code from @Mico, and second-handedly from @egreg, here is a small adaptation that has the descriptions of the steps left-aligned, which i think is what the question is really asking for.

i have added one step, which takes the math content of the first line of the alignment as an argument, and forces that line to a fixed width, which should accommodate the longest line in the group; the width needs to be determined empirically, but can be changed easily. the use of \mathclap requires the package mathtools, but since that automatically loads amsmath, i have simply substituted that package for the other.

\documentclass{article}
\usepackage{mathtools}
\newcounter{multialign}
\makeatletter
%% see http://tex.stackexchange.com/a/191379/5001 for the original definition of multialign
\newenvironment{multialign} 
  {%%\setcounter{multialign}{0}%
   \def\item{\refstepcounter{multialign}\themultialign.\qquad}%
   \start@align\tw@\st@rredtrue\m@ne}
  {\endalign}
\newcommand{\firstmaline}[1]{%
  \kern-1em \mathrlap{#1}\kern5cm}
\makeatother
\allowdisplaybreaks
\begin{document}
\section{Applying the Steps}

\textbf{Example:} Simplify \(x+3-2x+(4+2)^2+3x\)
\begin{multialign} 
\item
&\firstmaline{x+3+(4+2)^2+3x} &&&\\ 
& = x+3x+3+(4+2)^2 && \text{Rearrange the terms}\\
& = 4x + 3 + (4+2)^2 && \text{Addition (for $x$)}\\
& = 4x + 3 + (6)^2 && \text{Parentheses}\\
& = 4x + 3 + 36 && \text{Squaring}\\
& = 4x + 39 && \text{Addition}
\end{multialign}

\noindent \textbf{Example:} Simplify \(3x-5(4+3)^2-3x+8x\)
\begin{multialign}
\item
&\firstmaline{3x-5(4+3)^2-3x+8x} &&&\\
&= 3x-3x+8x-5(4+3)^2 && \text{Rearrange the terms}\\
&= 0+8x-5(4+3)^2 && \text{Subtraction (for $x$)} \\
&= 8x - 5(4+3)^2 && \text{Addition (for $x$)}\\
& = 8x - 5(7)^2 && \text{Parentheses}\\
& = 8x - 5(49) && \text{Squaring}\\
& = 8x - 245 && \text{Multiplication} \\
\end{multialign}

\end{document}

output of example code

  • Wait so for this one, you just switch the "&" symbols around? How do you know when to do this and when not too? – Gamerdue Jul 15 '14 at 17:22
  • @Gamerdue -- the order here is constrained by the way the command \firstmaline is defined. i defined it so that what's before the first & in the first line won't have any effect on how wide the space is before the alignment; all the width adjustments are made with \kerns of specific dimensions in the second column, which is the column that has the real effect on the positioning of the text descriptions. you implied in your earlier message that you may not have a lot of latex experience. don't worry -- understanding will come with time. – barbara beeton Jul 15 '14 at 17:38
  • Since I couldn't get the result you posted, here's what I did instead: \ \ \ \ \text{Rearrange the terms}\ for everything in the first example – Gamerdue Jul 15 '14 at 17:49