Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to make the traditional division? Like that:

a |b_
r  c
share|improve this question
    
possible duplicate of Decimal Long Division –  Werner May 13 '13 at 2:37
1  
@Werner I don't think this is really a duplicate; in a comment to my answer Fabricio specified that he needed a manual way to represent the division, so the xlop option (which is the suggestion in the possible duplicate) was not really an option in this case. –  Gonzalo Medina May 13 '13 at 2:59
add comment

2 Answers

up vote 12 down vote accepted

One option would be to use the xlop package:

\documentclass{report}
\usepackage{xlop}

\begin{document} 

\opidiv{25}{7}\qquad\opdiv{25}{7}

\end{document}

enter image description here

Manually, you can use an array:

\documentclass{article}

\newcommand\myrule[1]{\multicolumn{1}{| l}{#1}}

\begin{document}

\[
\begin{array}{rl}
478 & \myrule{7} \\
\cline{2-2}
58 & 68 \\
2
\end{array}
\]

\end{document}

enter image description here

If you are only interested in the dividend, divisor, quotient and remainder, you can define a two-argument command (quotient and remainder can be automatically calculated) along the lines of

\documentclass{article}
\usepackage{intcalc}


\newcommand\mydiv[2]{%
\ifnum#2>0
\[
\renewcommand\arraystretch{1.2}
\begin{array}{@{}r | l}
#1 & #2 \\
\cline{2-2}
\multicolumn{1}{r}{\intcalcMod{#1}{#2}} 
& 
\ifnum#1>0\relax
  \intcalcDiv{#1}{#2}
\else
  \number\numexpr\intcalcDiv{#1}{#2}-1\relax
\fi
\end{array}
\]
\else
\GenericWarning{}{Division Warning: "Please provide a positive integer as divisor"}
\fi
}


\begin{document}

\mydiv{478}{7}

\end{document}

enter image description here

share|improve this answer
    
I actualy need the manual way. Because i'm using an online latex editor to generate my outputs. –  Fabricio May 13 '13 at 1:25
1  
@Fabricio please see my updated answer. –  Gonzalo Medina May 13 '13 at 1:33
    
Thanks......!!! –  Fabricio May 13 '13 at 1:38
1  
@Fabricio You're welcome! I did another update to my answer taht could be of interest to you. –  Gonzalo Medina May 13 '13 at 1:42
    
@GonzaloMedina \numexpr division rounds: try \mydiv{478/8} –  egreg May 13 '13 at 8:22
show 2 more comments

For the simple diagrams you can do in this way:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\division}{smm}
 {
  \IfBooleanTF{#1}
   { \fabricio_division_inline:nn { #2 } { #3 } }
   { \fabricio_division:nn { #2 } { #3 } }
 }

\cs_new:Npn \fabricio_division_inline:nn #1 #2
 {
  #1=#2\cdot\int_div_truncate:nn { #1 } { #2 }
     + \int_mod:nn { #1 } { #2 }
 }
\cs_new_protected:Npn \fabricio_division:nn #1 #2
 {
  \begin{array}{r | l}
  #1 & #2 \\
  \cline{2-2}
  \multicolumn{1}{r}{\int_mod:nn { #1 } { #2 }} &
    \int_div_truncate:nn { #1 } { #2 }
  \end{array}
 }
\ExplSyntaxOff

\begin{document}
\[
\division*{1234}{42}
\qquad
\division{1234}{42}
\]
\end{document}

The *-form just prints the division in the form a=bq+r.

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.