2

I've had to ask a new question since I can't figure out how to post the code into the thread I'd opened.

I've tried manipulating the code Steven B. Segletes posted in Sharelatex to get what I want. However I cannot get it all lined up properly I'm not sure what's wrong.

Here's the code:

\documentclass{article}
\usepackage{tabstackengine,mathtools}
\stackMath
\setstacktabbedgap{1.5ex}
\setstackgap{S}{3pt}
\newcommand\showdiv[1]{\smash{\raisebox{1.5pt}{\scalebox{1.15}{)}}}#1}
\newcommand\laprule[1]{\rlap{\rshift\smash{\rule[-1pt]{#1}{.5pt}}}}
\makeatletter
\newcommand\rshift[1][0pt]{\hspace{\dimexpr#1+\tabbed@gap\relax}}
\makeatother
\begin{document}
\[
\tabbedShortstack[r] {x^2 & +5x & -2 \\
\laprule{90pt}&&\\
x-3  \showdiv {x^3}  +2x^2 & -17x & +6 \\
& +x^3 & -3x^2\\
&\laprule{55pt}&&\\
&& 5x^2 & -17x\\
&& 5x^2 & -15x\\
&\laprule{55pt}&&&&&&\\
&& -2x & +6&&\\
&& -2x & +6&&\\
&\laprule{55pt}&&\\
&&& 0
}
\]
\end{document}

enter image description here

cfr
  • 198,882
Brett
  • 41
  • 4
    What's your question? How to copy and paste properly with ShareLaTeX? It sounds like you're having a private conversation with someone else, and decided to post it in a public forum. – Teepeemm Jun 20 '17 at 19:30
  • 3
    you have just posted a question to the entire world addressed to "you" that seems a strange form of communication. – David Carlisle Jun 20 '17 at 19:51
  • I'm sorry its just that your site is so difficult to use unlike 99% of forums I've come across in the past. I was trying to contact someone via Private Message. I've edited my post. – Brett Jun 20 '17 at 20:55
  • 2
    There are no forms of private communication here on the site (https://tex.meta.stackexchange.com/questions/7314/). That said, using the polynom package isn't good enough? Try \documentclass{article} \usepackage{polynom} \begin{document} \polylongdiv{x^3+2x^2-17x-6}{x-3} \end{document}. – Torbjørn T. Jun 20 '17 at 21:29
  • No because I wanna have the sum in steps and the poly nom package (to my understanding) just dumps the entire sum in one go

    Brett

    – Brett Jun 20 '17 at 21:56
  • Can you please edit your question so it is addressed generally? Or, if you really only want to address one person, you could take it off site. – cfr Jun 20 '17 at 23:32
  • 1
    Each row of your stack is delimited by the double backslash, and each row should have an equal number of & column delimiters (they don't). Each column (delimited by &) will be aligned with the similar values from other rows. The only quirk here is that, because you are right aligning the columns, the \laprule should be applied in the column before where you actually want it to begin. So start by getting an equal number of & in each row, and then begin figuring out which column content gets aligned with other rows. – Steven B. Segletes Jun 21 '17 at 00:53

1 Answers1

3

To reiterate what I noted in my comment...

Each row of your stack is delimited by the \\, and each row should have an equal number of & column separators (they don't). Each column (separated by &) will be aligned with the similar values from other rows. The only quirk here is that, because you are right aligning the columns, the \laprule should be applied in the column before where you actually want it to begin. So start by getting an equal number of & in each row, and then begin figuring out which column content gets aligned with other rows.

Since you have 4 columns in the dividend plus the divisor for an additional column, the 5 required columns require a total of 4 & separators per row. In the MWE below, I have gone out of my way to align the & separators in the input to the stack, as well, so that you can see which column data gets co-aligned.

\documentclass{article}
\usepackage{tabstackengine,mathtools}
\stackMath
\setstacktabbedgap{1.5ex}
\setstackgap{S}{3pt}
\newcommand\showdiv[1]{\smash{\raisebox{1.5pt}{\scalebox{1.15}{)}}}#1}
\newcommand\laprule[1]{\rlap{\rshift[.1ex]\smash{\rule[-1pt]{#1}{.5pt}}}}
\makeatletter
\newcommand\rshift[1][0pt]{\hspace{\dimexpr#1+\tabbed@gap\relax}}
\makeatother
\begin{document}
\[
\tabbedShortstack[r] {
              &                 &x^2           & +5x  & -2 \\
\laprule{96pt}&                 &              &      &    \\
x-3           & \showdiv {~x^3} & +2x^2        & -17x & +6 \\
              & +x^3            & -3x^2        &      &    \\
\laprule{50pt}&                 &              &      &    \\
              &                 & 5x^2         & -17x &    \\
              &                 & 5x^2         & -15x &    \\
              &\laprule{54pt}   &              &      &    \\
              &                 &              & -2x  & +6 \\
              &                 &              & -2x  & +6 \\
              &                 &\laprule{43pt}&      &    \\
              &                 &              &      & 0
}
\]
\end{document}

enter image description here

  • Hi @Steven B. Segletes Thanks for taking the time to clear up how I'd use the "&" symbol. I was able to get the out put I needed. Almost. I can't quite figure out how to get the '-2' in 'x^2 +5x -2' to align with the '-17' right below it, it seems to align more with the 'x' of '17x' I cannot figure out how to post the code here so you can see what I'm talking about.

    Thanks Brett

    – Brett Jun 21 '17 at 16:55
  • I feel like just the top row needs to be left aligned – Brett Jun 21 '17 at 17:50
  • @Brett without seeing it, it is hard to say, but any given stack column can only have a single alignment, left, center, or right. Sometimes, when adjustments need to me made, one can add a \phantom to artificially take up space. – Steven B. Segletes Jun 21 '17 at 18:11
  • I wish this site wasn't built so deliberately hard to use and it'd just let you post a picture as a response like 90% of the forums. I don't see why not? Here's a link https://ibb.co/dDshCk – Brett Jun 21 '17 at 20:05
  • 1
    @Brett In the top row, use for that entry +5x\phantom{^2}. The \phantom takes up the space of ^2 without actually printing it out. Likewise 2\phantom{x} for the next column entry. – Steven B. Segletes Jun 21 '17 at 20:08
  • Fantastic! It worked like a charm! Thanks @Steven B. Segletes – Brett Jun 21 '17 at 20:29
  • @Brett Happy it worked. How to really say "thanks" on this site: If any answer (or question) on this site is useful to you, you may "upvote" it by clicking on the uparrow to the immediate left of the answer (or question). If, to one of your questions, a particular answer solves your problem better than the others, you may click the check mark to the left of the answer, to signal to other readers which of the answers to your question best served your needs. Clicking the check mark to an answer to one of your questions is called "accepting an answer." – Steven B. Segletes Jun 21 '17 at 20:34