1

I would like to code my own Lua(LaTeX) code to obtain periodic decimal divisions like the one below. I know the xlop package, but I want another formatting.

enter image description here

My question is just about formatting and the missing decorations in my MWE.

\documentclass{article}

\begin{document}

% -------------- % % -- 10 by 11 -- % % -------------- %

\begin{tabular}{*{7}{c}} 1 & 0 & & & 1 & 1 \ 1 & 0 & 0 & & \kern2pt0, & 9 & 0 \ && 1 \ && 1 & 0 \end{tabular}

\end{document}

Output obtained.

enter image description here

projetmbc
  • 13,315
  • I don't know about Lua and xlop but it looks like you need tikzmark to draw a rectangle around two cells of a tabular (possibly on the background or before the tabular is typeset) and then just an arc between those two nodes? You could also do it all in TikZ with a \matrix of nodes or just some well-placed nodes … – Qrrbrbirlbel Oct 23 '22 at 14:19
  • I just need some help about the formatting (Lua is easy to code). If you have one solution with TikZ matrix, it is ok for me. – projetmbc Oct 23 '22 at 14:23

1 Answers1

2

Here's an idea.

The first column of the TikZ-matrix is the left side, the second column is the right side of your diagram.

I'm using the width of a space which is accessible in PGFmath with width(" ") in multiple places:

  1. as the column sep,
  2. as the inner xsep and
  3. most importantly in the s style.

This way, we can say s=2 and it will shift the node about two digits to the right. With the default value of 1, you can also simply say s, s to shift it about two digits.

Similarly to the second column, you could also insert fake \0 to pad the left side of a node.

The anchor=base west left-aligns all nodes.

In the second column, I'm using \hphantom{0} to pad the right side of the node so that line from the append after command is long enough.

You could also do node family={text width=\tikzmatrixname, text width align=left} with my ext.node-families library.

Or you draw these lines after the matrix has been constructed and use the right border of the matrix (which fits tightly against the right-most node of the second column, i.e.

(m-2-x.north west) |- (m-2-x.south-|m.east)

Depending on the dynamic of these diagrams, it could be interesting to employ tikz-cd and use \arrow[uuuu, <half arc>] instead.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{
  matrix,
  calc,
}
\begin{document}
\begin{tikzpicture}[
 s/.style={xshift=#1*width("0 ")},
 s/.default=1, % shifts one digit to the right
 m/.style={fill=orange!10, draw=orange!50},
]
\matrix[
  matrix of nodes,
  column sep=2*width(" "),
  every outer matrix/.append style={inner sep=+0pt},
  /utils/exec=\def\,{\rlap{,}}%    % overwriting \, doesn't seem like a good idea
              \def\0{\hphantom{0}},% but it is local to the \matrix
  nodes={
    anchor=base west, % left-aligned
    inner xsep=.5*width(" ")
  },
  column 2/.append style={
    nodes={
      text depth=+0pt,% comma doesn't contribute to the node size,
                      % alternatively: \def\,{\smash{\rlap{,}}}
      outer sep=+0pt, % anchors on the actual border, just to be safe
      append after command={% draw west and south border of node
                            % overlay so that it doesn't contribute
                            % to the cell's size
        (\tikzlastnode.north west) edge[
          overlay, to path={|-(\tikzlastnode.south east)}]()}
    }
  },
] (m) {
 |[m]| 1 0     & 1   1 \0 \\
       1 0 0   & 0\, 9 0  \\
 |[s, s ]| 1   \\
 |[m,s=2]| 1 0 \\
};
\draw[m, fill=none]
  let \p{angle}=($(m-4-1.south)-(m-1-1.west)$) in
  (m-4-1.south) arc[% half arc between m-4-1.south and m-1-1.west
                  start angle={atan2(\y{angle},\x{angle})},
                  delta angle=-180,
                  radius=.5*veclen(\p{angle})];
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821