Numeración en celdas

Numeración en celdas

Quiero numerar mis celdas en una tabla en LaTeX. El resultado debería verse así. ingrese la descripción de la imagen aquí

¿Alguien sabe cómo hacer esto?

Respuesta1

Definí un nuevo entorno, con un argumento, el número de columnas, que numera automáticamente sus celdas:

\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}

ingrese la descripción de la imagen aquí

Respuesta2

Podrías definir un comando con un tabularentorno para usarlo dentro de tu 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}

ingrese la descripción de la imagen aquí

Al usar el paquete tikz puedes hacer algo como esto:

\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}

ingrese la descripción de la imagen aquí

Respuesta3

Con una matriz TikZ y \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}

ingrese la descripción de la imagen aquí

información relacionada