如何进行传统的划分?像这样:
a |b_
r c
答案1
一个选择是使用xlop
包裹:
\documentclass{report}
\usepackage{xlop}
\begin{document}
\opidiv{25}{7}\qquad\opdiv{25}{7}
\end{document}
手动地,你可以使用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}
如果你只对被除数、除数、商和余数感兴趣,你可以定义一个双参数命令(商和余数可以自动计算),如下所示
\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}
答案2
对于简单的图表,您可以按照以下步骤进行:
\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}
*-form 只是以 形式打印除法a=bq+r
。