3

I would like to insert some diagrams into a table, I know the scaling will be wrong but both files work separately just not together here is what I have so far.

\documentclass{article}

\usepackage{blindtext}

% remove spacing around date:
\usepackage{titling}
\predate{}
\postdate{}

\author{.}
\title{Place value}
\date{} % clear date

%Place value code
\newcounter{x}
\newlength{\x}
\setlength{\x}{.8cm}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\def\xangle{30}
\def\yangle{10}
\newcommand\xaxis{180+\xangle}
\newcommand\yaxis{-\yangle}
\newcommand\zaxis{90}
% The top side of a cube
\newcommand\topside[3]{
   \fill[fill=yellow!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift=   {(\yaxis:#2)},
   shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (180-\yangle:1) --++(180+\xangle:\x)--cycle;
 }
 % The left side of a cube
 \newcommand\leftside[3]{
  \fill[fill=orange!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (0,-1) --++ (180-\yangle:1) --(180-\yangle:1)--(0,0);
 }
 % The right side of a cube
 \newcommand\rightside[3]{
  \fill[fill=blue!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
   shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (0,-1)--(0,-1)--(0,0);
 }
 % The cube 
 \newcommand\cube[3]{
  \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
 }
 % Definition of \planepartition
 % To draw the following plane partition, just write \planepartition{ {a, b, c},  {d,e}     }.
 %  a b c
 %  d e
\newcommand\planepartition[2][0]{
  \setcounter{x}{-1}
    \foreach \a in {#2} {
         \addtocounter{x}{1}
         \setcounter{y}{-1}
          \foreach \b in \a {
           \addtocounter{y}{1}
            \setcounter{z}{-1}
             \addtocounter{z}{#1} %partition of the desired floor (layer)
              \ifnum \b>0
               \foreach \c in {1,...,\b} {
                \addtocounter{z}{1}
                 \cube{\value{x}}{\value{y}}{\value{z}}
       }\fi
    }
  }
}

 \begin{document}

 \maketitle
 \begin{table}
 \begin{tabular}{|c|c|c|c|c|c|c|c|}
 \hline
 Million& Hundred thousand & Tens Thousand & Thousand & Hundrends & Tens & Units\\
 \hline
 1,000,000 & 100,000 & 10,000 & 1,000 & 100 & 10 & 1\\
 \hline

 \begin{tikzpicture}[scale=0.5]
    \planepartition{{0},{1},{0}}\\% units
 &

  \begin{scope}[xshift=2cm,scale=0.5]
             \planepartition{{10,0,0},{0,0,0},{0,0}}% Tens
  \end{scope}\\
 &
   \begin{scope}[xshift=6cm, scale=0.5]
        \planepartition{{10,10,10,10,10,10,10,10,10,10}}% Hundreds
   \end{scope}\\
 &

  \begin{scope}[scale=0.5] %Tousands
     \planepartition{{10,10,10,10,10,10,10,10,10,10},    {10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10}}
       \end{scope}\\

 &

 t\\

 &

 t\\

 & 
  t\\
 
    \end{tikzpicture}\\
 \hline
 \end{tabular}
 \end{table}

 \end{document}

any help would be helpful, and if tidying up my code would be a bonus (but I know that's not what this forum is for).

1
  • I think you should either create separate tikzpicture environments in the different table cells or directly go with the inline \tikz{...} syntax instead. Spanning multiple columns in a single tikzpicture like this is - I believe - not supported
    – Raven
    Commented Jul 22, 2022 at 15:21

1 Answer 1

7

This code will enter the tikzpicture(s) into a tabular.

a

\documentclass{article}

\usepackage{blindtext}

\usepackage{tikz}% added <<<<<<<<<<<<<<<<<

\usepackage[left=1.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}

% remove spacing around date:
\usepackage{titling}
\predate{}
\postdate{}

\author{.}
\title{Place value}
\date{} % clear date

%Place value code
\newcounter{x}
\newlength{\x}
\setlength{\x}{.8cm}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\def\xangle{30}
\def\yangle{10}
\newcommand\xaxis{180+\xangle}
\newcommand\yaxis{-\yangle}
\newcommand\zaxis{90}
% The top side of a cube
\newcommand\topside[3]{
    \fill[fill=yellow!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift=   {(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (180-\yangle:1) --++(180+\xangle:\x)--cycle;
}
% The left side of a cube
\newcommand\leftside[3]{
    \fill[fill=orange!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (0,-1) --++ (180-\yangle:1) --(180-\yangle:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
    \fill[fill=blue!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (0,-1)--(0,-1)--(0,0);
}
% The cube 
\newcommand\cube[3]{
    \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}
% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c},  {d,e}     }.
%  a b c
%  d e
\newcommand\planepartition[2][0]{
    \setcounter{x}{-1}
    \foreach \a in {#2} {
        \addtocounter{x}{1}
        \setcounter{y}{-1}
        \foreach \b in \a {
            \addtocounter{y}{1}
            \setcounter{z}{-1}
            \addtocounter{z}{#1} %partition of the desired floor (layer)
            \ifnum \b>0
            \foreach \c in {1,...,\b} {
                \addtocounter{z}{1}
                \cube{\value{x}}{\value{y}}{\value{z}}
            }\fi
        }
    }
}

\begin{document}

\begin{table}
    \begin{tabular}{|c|c|c|c|}  
        \hline
        Million& Hundred thousand & Tens Thousand & Thousand \\
        \hline
        1,000,000 & 100,000 & 10,000 & 1,000 \\
        \hline%         
        \begin{tikzpicture}[scale=0.5]
            \planepartition{{0},{1},{0}}% units
        \end{tikzpicture}
        &       
        \begin{tikzpicture}
            \begin{scope}[xshift=2cm,scale=0.5]
                \planepartition{{10,0,0},{0,0,0},{0,0}}% Tens
            \end{scope}
        \end{tikzpicture}
        &
        \begin{tikzpicture}
            \begin{scope}[xshift=6cm, scale=0.5]
            \planepartition{{10,10,10,10,10,10,10,10,10,10}}% Hundreds
            \end{scope}
        \end{tikzpicture}
        &
        \begin{tikzpicture}
            \begin{scope}[scale=0.5] %Thousands
                \planepartition{{10,10,10,10,10,10,10,10,10,10},    {10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10},{10,10,10,10,10,10,10,10,10,10}}
            \end{scope}
        \end{tikzpicture}
        \\      
        \hline
    \end{tabular}
\end{table}
    
\end{document}

UPDATE

The code can be compacted by defining a new command \DrawCubes with a third parameter which is the scale.

\documentclass{article}

\usepackage{blindtext}

\usepackage{tikz}% added <<<<<<<<<<<<<<<<<

\usepackage[left=1.00cm, right=1.00cm, top=3.00cm, bottom=3.00cm]{geometry}

% remove spacing around date:
\usepackage{titling}
\predate{}
\postdate{}

\author{.}
\title{Place value}
\date{} % clear date

%Place value code
\newcounter{x}
\newlength{\x}
\setlength{\x}{.8cm}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\def\xangle{30}
\def\yangle{10}
\newcommand\xaxis{180+\xangle}
\newcommand\yaxis{-\yangle}
\newcommand\zaxis{90}
% The top side of a cube
\newcommand\topside[3]{
    \fill[fill=yellow!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift=   {(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (180-\yangle:1) --++(180+\xangle:\x)--cycle;
}
% The left side of a cube
\newcommand\leftside[3]{
    \fill[fill=orange!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (0,-1) --++ (180-\yangle:1) --(180-\yangle:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
    \fill[fill=blue!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
    shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (0,-1)--(0,-1)--(0,0);
}
% The cube 
\newcommand\cube[3]{
    \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}
% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c},  {d,e}     }.
%  a b c
%  d e
\newcommand\planepartition[2][0]{
    \typeout{ONE== #1}
    \typeout{TWO== #2}
    \setcounter{x}{-1}
    \foreach \a in {#2} {
        \addtocounter{x}{1}
        \setcounter{y}{-1}
        \foreach \b in \a {
            \addtocounter{y}{1}
            \setcounter{z}{-1}
            \addtocounter{z}{#1} %partition of the desired floor (layer)
            \ifnum \b>0
            \foreach \c in {1,...,\b} {
                \addtocounter{z}{1}
                \cube{\value{x}}{\value{y}}{\value{z}}
            }\fi
        }
    }
}

\newcommand{\DrawCubes}[3][0]{% added <<<<<<<<<<<<<<<<<<<<
    \begin{tikzpicture}[scale=#3]
        \setcounter{x}{-1}
        \foreach \a in {#2} {
        \addtocounter{x}{1}
        \setcounter{y}{-1}
        \foreach \b in \a {
        \addtocounter{y}{1}
        \setcounter{z}{-1}
        \addtocounter{z}{#1} %partition of the desired floor (layer)
        \ifnum \b>0
        \foreach \c in {1,...,\b} {
        \addtocounter{z}{1}
        \cube{\value{x}}{\value{y}}{\value{z}}
        }\fi
        }
        }
    \end{tikzpicture}
}

\begin{document}

\begin{table}
    \begin{tabular}{|c|c|c|c|}  
            \hline
            Unit & Ten & Hundred & Thousand \\
            \hline
            1 & 10 & 100 & 1,000 \\ \hline
            \DrawCubes{1}{0.5}% units 1x1
            &   \DrawCubes{10}{0.5}% Tens 1x10
            &   \DrawCubes{{10,10,10,10,10,10,10,10,10,10}}{0.5}%% Hundreds 10x10
            &   \DrawCubes{{10,10,10,10,10,10,10,10,10,10}, 
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10},
                    {10,10,10,10,10,10,10,10,10,10}}{0.5}% Thousands 10x10x10       
            \\      
            \hline
        \end{tabular}
    \end{table} 
\end{document}
1
  • thanks, I have obviously changed order so it fits with the table titles, but thank you very much!
    – Paul A
    Commented Jul 22, 2022 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .