答案1
我定义了一个新环境,它有一个参数,即列数,它会自动对单元格进行编号:
\documentclass[12pt,a4paper]{report}
\usepackage{array, siunitx, makebox}
\newcounter{cellctr}
\newenvironment{countcells}[1]{\setcounter{cellctr}{0}\setlength{\extrarowheight}{4pt}\tabular{|*{#1}{c<{\enspace \stepcounter{cellctr}\raisebox{1.5ex}{\scriptsize\makebox*{\scriptsize000}[l]{\num[minimum-integer-digits=4]{\thecellctr}}}}|}}}%
{\endtabular\setcounter{cellctr}{0}}
\begin{document}
\begin{countcells}{4}\hline%
A & B & C & D \\ \hline
E & F & G & H \\ \hline
\makebox*{H}{I} & J & K & L \\ \hline
\end{countcells}
\end{document}
答案2
您可以定义一个带有tabular
环境的命令并在表格中使用它:
\documentclass[12pt,a4paper]{report}
\newcommand{\mycell}[2]{\begin{tabular}{@{}c@{}c@{}}&\tiny #2\\\Large #1&\end{tabular}}
\begin{document}
\begin{tabular}{|c|c|c|c|}\hline
\mycell{A}{0001}& \mycell{B}{0002} & \mycell{C}{0003}& \mycell{D}{0004}\\\hline
\end{tabular}
\end{document}
通过使用 tikz 包你可以做这样的事情:
\documentclass[12pt,a4paper]{report}
\usepackage{tikz}
\makeatletter
\def\myFontSize{\f@size pt}
\makeatother
\def\BoxFactor{2.5}
\def\fsize{\myFontSize}
\newcommand{\mycontent}[2]{\begin{tabular}{@{}c@{}c@{}}&\tiny #2\\\Large #1&\end{tabular}}
\newcommand{\mycell}[3][black,1]{%
\foreach \item[count=\i from 1] in {#1}{\ifnum\i=1\xdef\mycolor{\item}\else\xdef\NoFLine{\item}\fi}
\begin{tikzpicture}[inner sep=0pt,outer sep=0pt]
\draw[-,thick,color={\mycolor}](0,0) --({\fsize*\BoxFactor},0)--({\fsize*\BoxFactor},{\fsize*\BoxFactor} )--(0,{\fsize*\BoxFactor}) coordinate (A);
\ifnum\NoFLine=1
\relax
\else
\draw[-,thick,color={\mycolor}](A)--(0,0);
\fi
\node at ({\fsize*\BoxFactor/2},{\fsize*\BoxFactor/2}) {\mycontent{#2}{#3}};
\end{tikzpicture}
}
\begin{document}
\noindent\(\mycell[blue,0]{A}{0001}\!\mycell{B}{0002}\mycell{C}{0003}\mycell{D}{0004}\)
\end{document}
答案3
使用 TikZ 矩阵和\foreach
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [
matrix of nodes,
column sep=-\pgflinewidth,
every node/.style={
draw,
align=center,
font=\bfseries\Huge,
text height=30pt,
text depth=10pt,
text width=40pt
},
] (mymatr) {
A & B & C & D \\
};
\foreach \i in {1, 2, ..., 4}
{\node[anchor=north east, font=\scriptsize]
at (mymatr-1-\i.north east) {\texttt{000\i}};}
\end{tikzpicture}
\end{document}