Forgot password
 Register account
View 2951|Reply 4

如何得到短除法?

[Copy link]

2

Threads

8

Posts

0

Reputation

Show all posts

xugaosong posted 2016-5-17 00:14 |Read mode
请教要输出短除法用什么方法?效果如图
VI4GNL9Z}Q0)N@UK~687}[4.png

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2016-5-17 03:24
用表格应该能实现,但比较麻烦,况且还有右边那箭头可能得另外画,既然这样,我决定干脆直接整个都用 tikz 来画算了,时间关系写得很随便,仅供参考。

代码: $type duanchufatest.tex (1.16 KB, Downloads: 1165)

用 xelatex 编译,效果:
QQ截图20160517032510.png

2

Threads

8

Posts

0

Reputation

Show all posts

original poster xugaosong posted 2016-5-17 07:12
回复 2# kuing


    辛苦了,我先学习学习.

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2025-6-26 00:53
今天讨论组群又提到这个短除法:



我就想起本帖,看了 9 年前 2# 的代码,是要人工计算每一行数值的,不太方便。

这次学习了 \tikzmath 的定义函数的玩法,实现了更自动化的画法:
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \begin{document}
  4. \usetikzlibrary{math,positioning}
  5. \tikzmath{
  6. int \q, \r, \i; coordinate \c; \c=(0,0);
  7. function dcf(\n,\d){
  8.     \i=0;
  9.     {\node (q0) at (\c) {$\n$};};
  10.     dcf2(\n,\d);
  11. };
  12. function dcf2(\n,\d){
  13.     if \n == 0 then {} else {
  14.         \q = \n/\d;
  15.         \r = \n-\d*\q;
  16.         {
  17.             \coordinate (tmp) at (q\i.south east);
  18.             \draw (q\i.north west) |- node[left,pos=0.25]{$\d$} (tmp);
  19.         };
  20.         \i = \i+1;
  21.         {
  22.             \node[below=0pt of tmp,anchor=north east] (q\i) {$\q$};
  23.             \node[right=0pt of q\i] (r\i) {$\cdots\r$};
  24.         };
  25.         dcf2(\q,\d);
  26.     };
  27. };
  28. }
  29. % 666 的 2 进制
  30. \tikz{\tikzmath{dcf(666,2);}}
  31. % 2048 的 3 进制,加箭头
  32. \tikz[>=latex]{
  33. \tikzmath{dcf(2048,3);}
  34. \draw[->] (r7.-90) -| (r1.north east);
  35. }
  36. \end{document}
Copy the Code
效果:


第二个图利用那些余数 node 的名字来加类似 2# 的箭头,(r1) 和 (r7) 就是(自上而下的)第一和第七个余数,商的则是 (q1) 等,(q0) 是最开头的被除数,都可以用。
另外,还可以在 dcf(...) 之前加一句 \c=(坐标); 来指定被除数的坐标(当需要一个图里画多个,或者图里还有其他东西时就可能有用(这里懒得演示))。

414

Threads

1641

Posts

15

Reputation

Show all posts

abababa posted 2025-6-26 09:49
kuing 发表于 2025-6-26 00:53
今天讨论组群又提到这个短除法:
我想这个能不能画出表格,然后把不需要的那些表格线擦掉。

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-20 19:47 GMT+8

Powered by Discuz!

Processed in 0.011966 seconds, 25 queries