7

I'm relatively new at LaTeX. I've read material online and have been practicing. However, I have not been able to find a solution to two of my questions. I'm hoping someone may be of assistance. This is what I have...

\begin{align}
-4(-5+6x) & = \hspace{1mm} 188  \\ 
(-4 \times -5) + (-4\times6x) & = \hspace{1mm} 188 \\
20-24x & = \hspace{1mm} 188 \\
-20\hspace{11.8mm}  & \hspace{3.5mm} -20 \\[-11pt]
\cline{1-2}
-24x & = \hspace{1mm} 168 \\
\dfrac{\cancel{-24} x}{\cancel{-24}} & =\dfrac{168}{-24}\\
x & = -7
\end{align}

My question is regarding the horizontal line. How can I minimize the distance? I would like for the horizontal line to line up, so to speak, directly under the -20 from line (4), that being the -20 on the left hand side of the equality. Also, I would like for it to end directly under the 0 from the -20 on line (4), that being the -20 on the right hand side. Furthermore, in line (6), how can I align the 4 from the right hand side of the denominator so that it is directly under the 8 of the numerator, that being the right hand side as well.

Thanks,

Miguel

2 Answers2

4

Alignments are possible (even fractions) using array:

enter image description here

\documentclass{article}
\usepackage{mathtools,cancel}% http://ctan.org/pkg/{mathtools,cancel}
\newcommand{\DFrac}[3][c]{\begin{array}{#1}#2\\\hline#3\end{array}}
\begin{document}

[ \setlength{\arraycolsep}{0pt} \renewcommand{\arraystretch}{1.2} \begin{array}{rr} -4(-5 + 6x) ={} & 188 \ (-4 \times -5) + (-4 \times 6x) ={} & 188 \ 20 - 24x ={} & 188 \ \multicolumn{2}{r}{\begin{array}{r} -20 \phantom{- 24x ={}} -20 \[0pt] \hline \end{array}} \ -24x ={} & 168 \ \DFrac{\cancel{-24} x}{\cancel{-24}} ={} & \DFrac[r]{168}{-24} \ x ={} & -7 \end{array} ]

\end{document}

Let's consider the code line-by-line

  • \setlength{\arraycolsep}{0pt}

    Remove the gap (by setting it to 0pt) between columns in an array environment.

  • \renewcommand{\arraystretch}{1.2}

    Increase the vertical spacing between rows inside a tabular/array. As reference, see Column and row padding in tables.

  • \begin{array}{rr}

    Start an array (tabular-like structure in math mode) that will have 2 columns, both of which are right-aligned.

  • -4(-5 + 6x) ={} & 188 \\

    First column content stretches up to &, while the second column stretches up to \\ - the line-breaking control. We use ={} since = is a binary relation. As such, it sets a specific space around it which differs from the space around a regular symbol, or a binary operator like + or -. As reference, see What is the difference between \mathbin vs. \mathrel? By providing an empty right-hand side {} for =, the appropriate spacing is established. Note that we set the column spacing to 0pt, so this spacing actually helps for making it work with 188.

  • (-4 \times -5) + (-4 \times 6x) ={} & 188 \\

    Similar to the above.

  • 20 - 24x ={} & 188 \\

    Similar to the above.

  • \multicolumn{2}{r}{\begin{array}{r}

    Here we start a \multicolumn that will span 2 columns and will be right-aligned as well. Inside of it we will create another array that now only contains a single column, also right-aligned. Why is this? Well, we eventually want to draw a horizontal rule that spans only the with of the contents of this structure, so we contain it in its own array.

  • -20 \phantom{- 24x ={}} -20 \\[0pt] \hline

    This sets -20, followed by a \phantom setting of -24x ={}. The \phantom setting creates a box (with width and height) that matches it's content but without printing it. Another way of viewing it would be that -24x ={} is set using white font colour. We also end the line with a [0pt] vertical gap, and insert a horizontal rule.

  • \end{array}} \\

    The \multicolumn is ended (it held the nested array).

  • -24x ={} & 168 \\

    Similar to what is mentioned above.

  • \DFrac{\cancel{-24} x}{\cancel{-24}} ={} & \DFrac[r]{168}{-24} \\

    Similar to what is mentioned above, yet we now insert a \DFrac. \DFrac is defined as an array itself containing two elements stacked on top of one another and an \hline inbetween; similar to a rudimentary \frac. The optional argument [r] is used as a replacement for the default centred view of the \DFrac. That is, it aligns the numerator/denominator of the fraction to the right, rather than centred.

  • x ={} & -7

    Similar to what was mentioned above.

  • \end{array}

    End the outer array structure.

Werner
  • 603,163
  • Werner - Thank you for your reply. As a relative newbie, your code is a bit too much for me at the moment. May I ask what literature you have read to become knowledgeable with LaTeX? In any event, you may be able to answer the remaining question I have posted above. In any event, thanks again :) – mignificent1 Jan 20 '14 at 19:56
  • @mignificent1: Are you referring to changing the distance of the horizontal rule? – Werner Jan 20 '14 at 19:59
  • Werner - I'm not sure what you mean by horizontal "rule?" I'm referring to the horizontal "line" that you are producing in your code. I want it to look exactly as yours, but by using my code. Is it possible? If you look at your code, the horizontal line extends underneath the first -20 and ends underneath the second -20. Again, as a newbie, \cline is in regard to columns, so I don't know if it would work for what I want. I hope this clarifies what I'm asking. In any event, thanks for the reply :) – mignificent1 Jan 20 '14 at 20:41
  • @mignificent1: I'm sorry, but I really don't follow. It would be easy to move the horizontal line up/down. – Werner Jan 22 '14 at 07:15
  • I'm not trying to move it up or down. I want it to look exactly like yours. If you look at both pairs of -20, the horizontal line is set perfectly, without extending the width of the page. Is it possible using my code to accomplish this? You're code is absolutely correct, but I'm unfamiliar with most of the code you're using. I hope this clarifies my question. Thanks in either event. :) – mignificent1 Jan 24 '14 at 03:25
  • @mignificent1: It may not be that easy with your code. I've added some explanation of my own code which might help inform you on what each line means. – Werner Jan 24 '14 at 05:05
  • @mignificent1 -- this comment is only about terminology. you express confusion about the term "rule" vs. "line". in typography, a "line" usually means a horizontal string of type. a "rule" is not a precept, but a straight line as if drawn with a ruler. (note the ambiguity regarding "line".) since (la)tex is a typesetting system, the terminology used in this forum is usually that which is specific to typography. – barbara beeton Jan 24 '14 at 06:00
3

One point about position of -20 is unclear for me, but the rest should be as you are expecting, I hope. Rather unstardard usage of align, but works.

\documentclass{article}
\usepackage{amsmath}
\usepackage{cancel}
\begin{document}

\newlength\mxx
\settowidth{\mxx}{$-24$}
\begin{align}
-4(-5+6x)  = \hspace{1mm} 188 & \\ 
(-4 \times -5) + (-4\times6x)  = \hspace{1mm} 188 &\\
20-24x  = \hspace{1mm} 188 &\\
%-20\hspace{11.8mm}  & \hspace{3.5mm} -20 \\[-11pt]
-20\hspace{11.8mm}    -20 &\\[-14pt]
\cline{1-1}
-24x  = \hspace{1mm} 168 &\\
 \dfrac{\cancel{-24} x}{\cancel{-24}}  = \dfrac{\makebox[\mxx][r]{168}}{\makebox[\mxx][r]{$-24$}}\!&\\
x  = -7 &
\end{align}

\end{document}

enter image description here

  • Przemyslaw Scherwent - Thank you for your response. It is greatly appreciated :) I have slightly modified your code. This is what I have, \newlength\mxx \settowidth{\mxx}{$-24$} \begin{align} -4(-5+6x) = \hspace{1mm} 188 \ (-4 \times -5) + (-4\times6x) = \hspace{1mm} 188 \ 20-24x = \hspace{1mm} 188 \ -20 \hspace{11.5mm}\hspace{3.5mm} -20 \[-11pt] \cline{1-1} -24x = \hspace{1mm} 168 \ \dfrac{\cancel{-24} x}{\cancel{-24}} = \dfrac{\makebox[\mxx][r]{168}}{\makebox[\mxx][r]{$-24$}}!&\ x = -7 & \end{align} \end{document} – mignificent1 Jan 20 '14 at 19:47
  • My only question is, is it possible with this new code to make the horizontal line begin at the -20 mark and end at the -20 mark on line 4? I think it has something to do with \cline{1-1}. – mignificent1 Jan 20 '14 at 19:53