格子或 Per Gelosia 乘法-如何避免使用 fp 包

格子或 Per Gelosia 乘法-如何避免使用 fp 包

有没有简单的方法可以改善节点特别是上行和右列距离的和谐性?

编辑 感谢egreg,节点更加和谐。

仍然 : 是否有可能避免使用 fp 包?

对于底部和左侧节点(结果),我直接使用乘法的答案,而不是沿对角线求和。有没有办法在不使用 fp 包的情况下得到乘法的答案(大数字)或者如何简单地沿对角线求和?使用矩阵……?

在此处输入图片描述

\documentclass{article}
\usepackage{tikz,xparse,xstring,fp}

\DeclareDocumentCommand{\split}{smmo}{%
    \xdef\Entree{#3}%
    \let\Sortie\empty%
    \IfBooleanTF #1
    {% sans étoile
        \loop
        \StrRight{\Entree}{#2}[\tmp]%
        \edef\Sortie{\Sortie,\tmp}%
        \StrGobbleRight{\Entree}{#2}[\Entree]%
        \unless\ifx\Entree\empty
        \repeat
        \StrGobbleLeft{\Sortie}{1}[\Sortie]%
    }
    {% avec étoile dans l'ordre inverse
        \loop
        \StrRight{\Entree}{#2}[\tmp]%
        \edef\Sortie{\tmp,\Sortie}%
        \StrGobbleRight{\Entree}{#2}[\Entree]%
        \unless\ifx\Entree\empty
        \repeat
        \StrGobbleRight{\Sortie}{1}[\Sortie]%
    }
    \IfNoValueTF{#4}{\Sortie}{\edef#4{\Sortie}}
    }


\usetikzlibrary{shapes}
\pgfkeys{/tikz/.cd,
    PGms/.store in=\PGms,
    PGms=.8
}
\tikzset {
    convert/.style 2 args={
        minimum size=\PGms cm,draw,outer sep=0pt,
        append after command={
            \pgfextra{
            \pgfinterruptpath
            \path (\tikzlastnode.north west)
                node[inner sep=2pt,anchor=north west]{#1};
            \path (\tikzlastnode.south east)
                node[inner sep=2pt,anchor=south east]{#2};
            \draw[help lines] (\tikzlastnode.south west)
            -- (\tikzlastnode.north east);
            \endpgfinterruptpath
            }
        }
    }
}


\newcommand{\PerGelosia}[3][1]{%
\split{#1}{#2}[\StringH]    
\split*{#1}{#3}[\StringV]   

\node[minimum size=\PGms cm,outer sep=0pt] (00) at (0,0) {} ;

\foreach \h [count=\Y from 1,count=\y from 0] in \StringH {%
\node[anchor=north,minimum size=\PGms cm,outer sep=0pt]
                                (0\Y) at (0\y.south) {} ;
\node[anchor=west] at (0\Y.west) {\h} ; }
\edef\NbLgn{\Y} % nb de lignes

\foreach \v [count=\X from 1,count=\x from 0] in \StringV {%
\node[anchor=east,minimum size=\PGms cm,outer sep=0pt]
                                (\X0) at (\x0.west) {} ;
\node[anchor=south] at (\X0.south) {\v} ;   }
\edef\NbCol{\X} % nb de colonnes

\foreach \h [count=\Y from 1,count=\y from 0] in \StringH {%
\foreach \v [count=\X from 1,count=\x from 0] in \StringV {%

    \FPmul\Prod\v\h
    \FPclip\Prod\Prod
    \StrGobbleRight{\Prod}{#1}[\Prodg]
    \StrRight{\Prod}{#1}[\Prodd]
    \ifx\Prodg\empty\def\Prodg{0}\fi

    \node[anchor=east,convert={\Prodg}{\Prodd}] (\X\Y) at (\x\Y.west) {} ;
}}

\FPmul\Prod{#2}{#3}
\FPclip\Prod\Prod
\StrGobbleRight{\Prod}{#1*\NbCol}[\Prodg]
\StrRight{\Prod}{#1*\NbCol}[\Prodd]

\split*{#1}{\Prodd}[\StringH]   
\foreach \h [count=\Y from 1,count=\y from 0] in \StringH {%
    \begin{scope}[shift={(\Y\NbLgn.south)}]
    \draw[->,>=stealth] (1.5pt,1.5pt)--(-5pt,-5pt)
        node[anchor=north east,inner sep=1pt] {\h};
    \end{scope} ;
}

\split{#1}{\Prodg}[\StringV]    
\foreach \v [count=\X from 1,count=\x from 0] in \StringV {%
    \begin{scope}[shift={(\NbCol\X.west)}]
    \draw[->,>=stealth] (1.5pt,1.5pt)--(-5pt,-5pt)
        node[anchor=north east,,inner sep=1pt] {\v};
    \end{scope} ;
}
}


\begin{document}
\begin{tikzpicture}[PGms=.95]
\PerGelosia[3]{890432}{6513782}
\end{tikzpicture}
\end{document}

相关内容