6

Is there a way to create something that looks like this?

a busy cat

I tried it:

\documentclass[10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[
    rotate=135,
    every label/.append style={text depth=+0pt},
    label position=center,
   % every cell/.style={fill=gray!25},
   % column 3/.style={fill=red!25},
   % row 5/.style={fill=green!25},
   % cell 2-2/.style={fill=gray},
   % cell 3-2/.style={fill=gray!50},
    ]
\foreach \jRow[count=\jCount from 1, remember=\mCount] in {%
        0,%
        {15750,0},%
        {7875,2625,0},%
        {9375,4375,750,0},%  
        {11875,7125,2500,1000,$A^{1}B^{1}$},%
        {15125,10500,5375,3500,5000,$C^{1}$},%
        {15125,10500,5375,3500,5000,0,$A^{1}$}%
    } {
    \foreach \mCell[count=\mCount from 1, remember=\mCount] in \jRow {
        \node[
            diamond,
            minimum size=1.414cm+0.4\pgflinewidth,
            draw,
            every cell/.try,
            row \jCount/.try,
            column \mCount/.try,
            cell \jCount-\mCount/.try,
            label={\pgfmathprintnumber{\mCell}},
            alias=@lastnode,
            alias=@lastrow-\mCount
        ] at (\mCount-.5,\jCount-.5) {};
        \ifnum\mCount=1
            %\path [late options={name=@lastnode, label=above left:$\jCount$}];
        \fi
    }
       % \path [late options={name=@lastnode, label=above:$a_\jCount$}];
    }
  %  \foreach \mCountExtra in {1,...,\mCount}
   %     \path [late options={name=@lastrow-\mCountExtra, label=above right:$\mCountExtra$}];
\end{tikzpicture}
\end{document}

I got Errors:

"! Package PGF Math Error: Could not parse input '$A^{1}B^{1}$' as a floating po
int number, sorry. The unreadable part was near '$A^{1}B^{1}$'.."

1 Answers1

6

The use of label={\pgfmathprintnumber{\mCell}} suggests that all \mCell contents are numeric, which is not true in your case. So, simply use label={\mCell} to print the alphanumeric values in \mCell.

\documentclass[10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[
    rotate=135,
    every label/.append style={text depth=+0pt},
    label position=center,
   % every cell/.style={fill=gray!25},
   % column 3/.style={fill=red!25},
   % row 5/.style={fill=green!25},
   % cell 2-2/.style={fill=gray},
   % cell 3-2/.style={fill=gray!50},
    ]
\foreach \jRow[count=\jCount from 1, remember=\mCount] in {%
        0,%
        {15750,0},%
        {7875,2625,0},%
        {9375,4375,750,0},%  
        {11875,7125,2500,1000,$A^{1}B^{1}$},%
        {15125,10500,5375,3500,5000,$C^{1}$},%
        {15125,10500,5375,3500,5000,0,$A^{1}$}%
    } {
    \foreach \mCell[count=\mCount from 1, remember=\mCount] in \jRow {
        \node[
            diamond,
            minimum size=1.414cm+0.4\pgflinewidth,
            draw,
            every cell/.try,
            row \jCount/.try,
            column \mCount/.try,
            cell \jCount-\mCount/.try,
            label={\mCell},
            alias=@lastnode,
            alias=@lastrow-\mCount
        ] at (\mCount-.5,\jCount-.5) {};
        \ifnum\mCount=1
            %\path [late options={name=@lastnode, label=above left:$\jCount$}];
        \fi
    }
       % \path [late options={name=@lastnode, label=above:$a_\jCount$}];
    }
  %  \foreach \mCountExtra in {1,...,\mCount}
   %     \path [late options={name=@lastrow-\mCountExtra, label=above right:$\mCountExtra$}];
\end{tikzpicture}
\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127