![将 Tikz 图表插入表格](https://linux22.com/image/452766/%E5%B0%86%20Tikz%20%E5%9B%BE%E8%A1%A8%E6%8F%92%E5%85%A5%E8%A1%A8%E6%A0%BC.png)
我想在表格中插入一些图表,我知道缩放比例会不对,但两个文件可以单独工作,只是不能一起工作,这就是我目前所得到的。
\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}
任何帮助都会有帮助,如果整理我的代码会是一个奖励(但我知道这不是这个论坛的目的)。
答案1
此代码将把tikzpicture
(s)输入到表格中。
\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}
更新
\DrawCubes
可以通过定义一个带有第三个参数(即比例)的新命令来压缩代码。
\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}