7

I am writing a thesis document in Latex and I want some text to be displayed as shown in the attached image:-

Math

I have created my own class file. I tried implementing the existing posts but couldn't modify them to get the result i want. Please guide me on this.

  • 1
    Did you see this related suggested on the right panel of the page? http://tex.stackexchange.com/q/11702/14757 – Sigur Jul 22 '15 at 16:21

3 Answers3

9

This can be done using an array:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\renewcommand\arraystretch{1.2}
\begin{array}{c@{}c@{\,}c@{\,}c@{\,}c@{\,}ccl}
& \makebox[0pt]{\raisebox{-.5\normalbaselineskip}[0pt][0pt]{$\times$}} & & 1 & 2 & 3 \\
& & & 4 & 5 & 6 \\
\cline{3-6}
& & & 7 & 3 & 8 & & \text{(this is $123 \times 6$.)} \\
+& & 6 & 1 & 5 &  & & \text{(this is $123 \times 5$, shifted one position to the left.)} \\
& 4 & 9 & 2  & & & & \text{(this is $123 \times 4$, shifted one position to the left.)} \\
\cline{1-6}
& 5 & 6 & 0 & 8 & 8
\end{array}
\]

\end{document}

enter image description here

With the arydshln package one can get the double dashed line above the result:

\documentclass{article}
\usepackage{amsmath}
\usepackage{arydshln}

\setlength\dashlinedash{5pt}
\setlength\dashlinegap{2.5pt}

\begin{document}

\[
\renewcommand\arraystretch{1.2}
\begin{array}{c@{}c@{\,}c@{\,}c@{\,}c@{\,}ccl}
& \makebox[0pt]{\raisebox{-.5\normalbaselineskip}[0pt][0pt]{$\times$}} & & 1 & 2 & 3 \\
& & & 4 & 5 & 6 \\
\cline{3-6}
& & & 7 & 3 & 8 & & \text{(this is $123 \times 6$.)} \\
+& & 6 & 1 & 5 &  & & \text{(this is $123 \times 5$, shifted one position to the left.)} \\
& 4 & 9 & 2  & & & & \text{(this is $123 \times 4$, shifted one position to the left.)} \\
\cdashline{1-6}\\[-1.09\normalbaselineskip]\cdashline{1-6}
& 5 & 6 & 0 & 8 & 8
\end{array}
\]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Is there some extra space between 5 and 6 in the result? – Sigur Jul 22 '15 at 16:34
  • @Sigur Yes, there was. I killed it. – Gonzalo Medina Jul 22 '15 at 16:40
  • @GonzaloMedina, pour space. Didn't survive too much... lol I never imagined that the problem was that \times. – Sigur Jul 22 '15 at 16:42
  • @Sigur Thanks for noticing that... I totally missed it .. – Shray Sharan Jul 22 '15 at 16:45
  • @Sigur I decided to give the space another chance :) Now it is in company of some companion spaces, and I think the result looks better. – Gonzalo Medina Jul 22 '15 at 16:48
  • @GonzaloMedina, yes, nice. What about two + signs on the right (like \times) to show the addition? – Sigur Jul 22 '15 at 16:49
  • @Sigur Might be. The inetrested reader can add it ;) – Gonzalo Medina Jul 22 '15 at 16:53
  • 1
    @Sigur On a second thought, I added it. Yes, it was in the image in the question. – Gonzalo Medina Jul 22 '15 at 16:57
  • @GonzaloMedina, : How can i get the double dotted lines above the result as it is there in the image.... And for adding the + symbol, should i just add a & + in that command line? It is throwing an error – Shray Sharan Jul 22 '15 at 17:01
  • @ShraySharan the + sign has been added in the last update. For dotted lines, use the hhline package. I'll update the answer with the dotted line in some minutes. – Gonzalo Medina Jul 22 '15 at 17:02
  • @ShraySharan You're welcome. Answer updated with the dotted line. Don't forget that, if you consider an answer solved your problem, you can (after a sensible wait for other possible answers) mark it as accepted by clicking the checkmark to its left. In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Jul 22 '15 at 17:12
  • @GonzaloMedina The code is throwing an error: ! Undefined control sequence. \cdashline – Shray Sharan Jul 22 '15 at 17:22
  • @ShraySharan You need to load the package \usepackage{arydshln}. Do you have it installed? – Gonzalo Medina Jul 22 '15 at 17:22
  • @GonzaloMedina Yes sir I have it installed... Sorry i missed including the package. Is this the only way i can get a dotted line becuase it looks a little different from what i want as an output – Shray Sharan Jul 22 '15 at 17:26
  • @ShraySharan Try playing with the values [1pt/1pt] in \cdashline{1-6}[1pt/1pt]\\[-\normalbaselineskip]\cdashline{1-6}[1pt/1pt] (as I suggested in the answer) to see if you can get the desired final look. By the way, how do you expect the dotted line to be? – Gonzalo Medina Jul 22 '15 at 17:28
  • @GonzaloMedina It's there in my question. That is how i want it to look.. The reason i want it to look similar to that is the thesis office wants us to follow the guidelines exactly. – Shray Sharan Jul 22 '15 at 17:34
  • @ShraySharan I see. I updated the answer. Is it better now? – Gonzalo Medina Jul 22 '15 at 17:41
  • @GonzaloMedina Yes sir.... It looks much better... Can you please tell me how can i alter the length of this dotted line? – Shray Sharan Jul 22 '15 at 17:52
  • @ShraySharan In \cdashline{1-6} the 1-6 means spanning from column 1 to column 6. Change those values according to your needs. – Gonzalo Medina Jul 22 '15 at 17:54
3

The deleted answer of A. Allet was in the right direction, but the xlop package not only can make automatically the multiplication. It can also show the shifted positions, as well as include comments with \oplput and \oprput:

MWE

\documentclass{article}
\usepackage{xlop}
\begin{document}
\opmul[displayshiftintermediary=all]{123}{456}
\oplput(1,3){(this is $123 \times 6$.)}
\oprput(-5,2){$+$}
\oplput(1,2){(this is $123 \times 5$, shifted one position to the left.)}
\oplput(1,1){(this is $123 \times 4$, shifted two positions to the left.)}
\end{document}

BTW, the inserted comments can be also an automatic multiplication so any mistyping could be more evident:

MWw2

\documentclass{article}
\usepackage{xlop,xcolor}
\begin{document}
\opmul[displayshiftintermediary=all]{123}{456}
\oplput(1,3){(\opmul[style=text]{123}{6})}
\oplput(1,2){(\opmul[style=text]{123}{5})}
\oplput(1,1){(\opmul[style=text]{123}{4})}
\end{document}
Fran
  • 80,769
0

you can use the xlop package

http://distrib-coffee.ipsl.jussieu.fr/pub/mirrors/ctan/macros/generic/xlop/doc/xlop-doc.pdf

page 15-16

rpapa
  • 12,350