셀 번호 매기기

셀 번호 매기기

LaTeX의 테이블에서 셀에 번호를 매기고 싶습니다. 결과는 다음과 같습니다. 여기에 이미지 설명을 입력하세요

누군가 이 작업을 수행하는 방법을 알고 있습니까?

답변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}

여기에 이미지 설명을 입력하세요

관련 정보