有没有一种合理的方式来形象化地展示“德国风格”的分裂

有没有一种合理的方式来形象化地展示“德国风格”的分裂

我需要以“德国风格”可视化部门。我设法使用 TikZ 做到了,但这是一项艰巨的工作!

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[start chain=going below,node distance=-2mm]
\node [on chain] {$\frac{1}{3} = 1:3 = 0,3333 = 0,\overline{3}$};
\node [on chain,xshift=-3em,yshift=0.8ex] {10};
\node [on chain,xshift=.5em] {10};
\node [on chain,xshift=.5em] {10};
\node [on chain,xshift=.5em] {10};
\node [on chain] {$\vdots$};
\end{tikzpicture}

\begin{tikzpicture}[start chain=going below,node distance=-2mm]
\node [on chain] {$\frac{1}{7} = 1:7 = 0,\overline{142857}$};
\node (s) [on chain,xshift=-2.1em,yshift=1ex] {10};
\node [on chain,xshift=.5em] {30};
\node [on chain,xshift=.5em] {20};
\node [on chain,xshift=.5em] {60};
\node [on chain,xshift=.5em] {40};
\node [on chain,xshift=.5em] {50};
\node (e) [on chain,xshift=.5em] {10};
\draw (e) edge[bend left=60,ultra thick,->] (s);
\end{tikzpicture}
\end{document}

姆韦

你知道如何在不“手动”优化的情况下做到这一点吗?

是的,我知道 xlop,但那是法国的方式

答案1

更新在底部扩展中添加了任意分母。此外,箭头也略有改进。未使用任何包。

从评论中移出:12000/17000 的情况在经济上很难实现。这里的代码没有看到分数不是不可约的,因此周期的实际开始时间早于输出中显示的。我认为我不会为第一个减少的分数添加额外的层。124/3072 示例也是如此。士气:将其应用于不可约分数以获得周期的实际开始时间。



没有辅助包。好吧,我用过xinttools,但那不是一个包,它更像是一个强制的包裹。(请耐心等待……)

xinttools其实,不需要再读一遍,只需替换\xintloop\loop...

主要的限制是,我假设分母为 10 的素数,因此周期立即开始。

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{chains}
% \usepackage{xint}% well let's do it with TeX numbers
\usepackage{xinttools}% but with some \xintloop, else where is the fun?


\makeatletter
\chardef\f@@r 4
\newcommand\GermanMaxSteps{20}

\newcommand\GermanDivision[2]{% assume A/B two integers with 0 < A < B
  % assume B is prime with 10, so period starts immediately
\begin{tikzpicture}[start chain=going below,node distance=-2mm]%
    \def\GerDiv@digits{}%
    \def\GerDiv@periodfound{0}%
    \count\tw@ #1
    \count6 \count\tw@
    \count@ \z@
    \toks@ {}%
    \xintloop
       \multiply\count\tw@ 10
       \count\f@@r \count\tw@
       \divide\count\f@@r #2
       \edef\GerDiv@digits{\GerDiv@digits\the\count\f@@r}%
       \multiply\count\f@@r #2
       \advance\count\tw@ -\count\f@@r
    \ifnum\count6=\count\tw@
       \def\GerDiv@periodfound{-1}%
    \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em] {\llap{$\the\count\tw@0$}};}%
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
    \fi
    \advance\count@ \@ne
    \ifnum\count@ < \GerDiv@periodfound\GermanMaxSteps\space
    \repeat
    \if0\GerDiv@periodfound
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@digits\dots$}};
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
        \node [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};
        \the\toks@
        \node [on chain] {\llap{$\vdots$}};
    \else
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\overline{\GerDiv@digits}$}};
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
        \node (s) [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};
        \the\toks@
        \node [on chain,xshift=.5em] {\llap{$#10$}};
        \node (e) [on chain, xshift=-1.5em, yshift=+1ex] {};
        \draw (e) edge[bend left=60,ultra thick,->] ([xshift=-1em, yshift=-.5ex]s);
    \fi
\end{tikzpicture}%
}%

\begin{document}

\GermanDivision {1}{3}

\GermanDivision {1}{7}

\GermanDivision {13}{49}

% \GermanDivision {13}{14}% no 14 not prime with 10!... can not find period

%\GermanDivision{11}{13}

%\GermanDivision{23}{27}

\GermanDivision{13}{17}
\end{document}

在此处输入图片描述


更新答案

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{chains}

\makeatletter
\chardef\f@@r 4
\newcommand\GermanMaxSteps{20}

\newcommand\GermanDivision[2]{% assume A/B two integers with 0 < A < B
\begin{tikzpicture}[start chain=going below,node distance=-2mm]%
    \def\GerDiv@start{}%
    \def\GerDiv@digits{}%
    \def\GerDiv@periodfound{0}%
% EXTRA ANNOYING HANDLING OF CASES WITH B NOT PRIME WITH 10
\count@ \z@
\count\tw@\z@
\count\f@@r #2 % denominator (scratch register)
\loop
\ifodd\count\f@@r
\else
  \divide\count\f@@r\tw@
  \advance\count@\@ne
\repeat
\loop
\ifnum\numexpr\count\f@@r-5*(\count\f@@r/5)=\z@
  \divide\count\f@@r 5
  \advance\count\tw@\@ne
\repeat
\count8 \count@
\ifnum\count\tw@>\count@
  \count8 \count\tw@
\fi
%
    \count@ \z@
    \count\tw@  #1 % (current) numerator
    \count\f@@r #2 % (fixed) denominator
    \toks@ {}%
%
% this does not modify \count8...
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
%
\ifnum\count8>\z@
  \toks@{\node [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};}%
\else
  \toks@{\node (s) [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};}%
\fi
\loop
\ifnum\count8>\z@
\advance\count@\@ne
       \multiply\count\tw@ 10
       \count6 \count\tw@
       \divide\count6 \count\f@@r
       \edef\GerDiv@start{\GerDiv@start\the\count6}%
       \multiply\count6 \count\f@@r
       \advance\count\tw@ -\count6
  \ifnum\count8=\@ne
    \ifnum\count\tw@>\z@
       \edef\GerDiv@temp{\noexpand\node (s) [on chain,xshift=.5em]
                         {\noexpand\llap{$\the\count\tw@0$}};}%
    \else
       \def\GerDiv@temp{\node [on chain,xshift=.5em]
                                 {\llap{$0\phantom{0}$}};}%
    \fi
  \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em]
         {\noexpand\llap{$\the\count\tw@0$}};}%
  \fi
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
\advance\count8 \m@ne
\repeat
%
    \count6 \count\tw@ % to identify period
% CHECK IF FRACTION IS A DECIMAL NUMBER
\ifnum\count\tw@=\z@
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start$}};
        \the\toks@
\else
    \loop
       \multiply\count\tw@ 10
       \count8 \count\tw@
       \divide\count8 \count\f@@r
       \edef\GerDiv@digits{\GerDiv@digits\the\count8}%
       \multiply\count8 \count\f@@r
       \advance\count\tw@ -\count8
    \ifnum\count6=\count\tw@
       \def\GerDiv@periodfound{-1}%
    \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em] {\noexpand\llap{$\the\count\tw@0$}};}%
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
    \fi
    \advance\count@ \@ne
    \ifnum\count@ < \GerDiv@periodfound\GermanMaxSteps\space
    \repeat
%
    \if0\GerDiv@periodfound
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start\GerDiv@digits\dots$}};
        \the\toks@
        \node [on chain] {\llap{$\vdots$}};
    \else
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start\overline{\GerDiv@digits}$}};
        \the\toks@
        \node [on chain,xshift=.5em] {\llap{$\the\count\tw@0$}};
        \setbox\z@\hbox{$\the\count\tw@0$}%
        \node (e) [on chain, xshift=-\wd0, yshift=+1ex] {};
        \draw (e) edge[bend left=60,ultra thick,->] ([xshift=-\wd0, yshift=-.5ex]s);
    \fi
\fi
\end{tikzpicture}%
}%

\usepackage{multicol}
\begin{document}\pagestyle{empty}

\begin{multicols}2
  \GermanDivision {1}{3}

  \GermanDivision {1}{7}

  \GermanDivision {13}{49}

  \GermanDivision {13}{14}

  \GermanDivision{13}{17}

  \GermanDivision{12}{17}

  \GermanDivision{12000}{17000}

  \GermanDivision{12}{170}

  \GermanDivision{13}{96}

  \GermanDivision{13}{9600}

  \GermanDivision{3}{1400}

  \GermanDivision{1}{96}

  \GermanDivision{1}{128}

  \GermanDivision{123}{1024}

  \GermanDivision{123}{3072}

  \GermanDivision{124}{3072}

  \GermanDivision{125}{3072}

  \GermanDivision{125}{168}

  \GermanDivision{125001}{167999}
\end{multicols}
\thispagestyle{empty}
\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

答案2

它不包括箭头,但它可以以多种不同的风格进行划分(包括德语):https://ctan.kako-dev.de/macros/latex/contrib/longdivision/longdivision_manual.pdf

这是您可能需要的文档的图像:

文档图片

相关内容