如何用乳胶对 longtable 中的单元格进行编号?

如何用乳胶对 longtable 中的单元格进行编号?

在此处输入图片描述

\begin{longtable}{|p{7cm}|p{10cm}|}
    \hline  
    \begin{tikzpicture} %1
        \coordinate[label = below:$A$] (A) at (0,0);
        \coordinate[label = above:$B$] (B) at (0,3);
        \coordinate[label = above:$C$] (C) at (6,3);
        \coordinate[label = below:$D$] (D) at (6,0);
        \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
        \tkzLabelSegment[left](A,B){$3$};
        \tkzLabelSegment[above](B,C){$6$};
    \end{tikzpicture} & \\
    \hline 
    \begin{center}
    \begin{tikzpicture} %2
        \coordinate[label = below:$A$] (A) at (0,0);
        \coordinate[label = above:$B$] (B) at (0,3);
        \coordinate[label = above:$C$] (C) at (3,3);
        \coordinate[label = below:$D$] (D) at (3,0);
        \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
        \tkzMarkSegment[mark = |](A,B);
        \tkzMarkSegment[mark = |](B,C);
        \node at (1.5, 1.5){$P=36$};        
    \end{tikzpicture} \end{center}& \\
    \hline
\end{longtable}

答案1

与。{NiceTabular}nicematrix

我已经获取了您的代码(我将其放在p{3cm}了序言中而不是p{10cm}为了适应页面宽度)。

我已替换{longtable}{NiceTabular}

\CodeAfter我在环境中添加了 Tikz 指令{NiceTabular}来绘制带有数字的小方块:

    \begin{tikzpicture}
    \node at (1-|1) [below right] { 1 } ;
    \draw (1-|1) rectangle ++(5mm,-5mm) ; 
    \node at (2-|1) [below right] { 2 } ;
    \draw (2-|1) rectangle ++(5mm,-5mm) ; 
    \end{tikzpicture}

以下是完整的代码。

\documentclass{article}
\usepackage{geometry}
\usepackage{nicematrix}
\usepackage{tikz,tkz-euclide}


\begin{document}


\begin{NiceTabular}{|p{7cm}|p{3cm}|}
    \hline  
    \begin{tikzpicture} %1
        \coordinate[label = below:$A$] (A) at (0,0);
        \coordinate[label = above:$B$] (B) at (0,3);
        \coordinate[label = above:$C$] (C) at (6,3);
        \coordinate[label = below:$D$] (D) at (6,0);
        \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
        \tkzLabelSegment[left](A,B){$3$};
        \tkzLabelSegment[above](B,C){$6$};
    \end{tikzpicture} & \\
    \hline 
    \begin{center}
    \begin{tikzpicture} %2
        \coordinate[label = below:$A$] (A) at (0,0);
        \coordinate[label = above:$B$] (B) at (0,3);
        \coordinate[label = above:$C$] (C) at (3,3);
        \coordinate[label = below:$D$] (D) at (3,0);
        \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
        \tkzMarkSegment[mark = |](A,B);
        \tkzMarkSegment[mark = |](B,C);
        \node at (1.5, 1.5){$P=36$};        
    \end{tikzpicture} \end{center}& \\
    \hline
\CodeAfter
    \begin{tikzpicture}
    \node at (1-|1) [below right] { 1 } ;
    \draw (1-|1) rectangle ++(5mm,-5mm) ; 
    \node at (2-|1) [below right] { 2 } ;
    \draw (2-|1) rectangle ++(5mm,-5mm) ; 
    \end{tikzpicture}
\end{NiceTabular}

\end{document}

上述代码的输出

答案2

就我在您的图片中看到的情况而言,我认为您不需要表格,只需要一个tikzpicture带有几个的表格scopes,每个表格scope都充当一个单元格。

我改变了你的坐标,因为我认为将原点放在每个“单元”的中心更简单。

这个想法是这样的:

\documentclass{article}
\usepackage{lipsum} % dummy text
\usepackage{tikz,tkz-euclide}

\begin{document}
\lipsum[1][1-2]
\begin{figure}[ht]\centering
\begin{tikzpicture}[scale=0.75]
\def\sepx{8}
\def\sepy{6}
\foreach\x in {1,2} \foreach\y in {1,2,3}
{
  \pgfmathtruncatemacro\n{3*\x+\y-3}
  \draw (\x*\sepx-\sepx+0.8,-\y*\sepy+\sepy) |-++ (-0.8,-0.8);
  \node at (\x*\sepx-\sepx+0.4,-\y*\sepy+\sepy-0.4) {$\n$};
}
\draw (0,0) grid[xstep=\sepx,ystep=\sepy] (16,-18);
%1
\begin{scope}[shift={(0.5*\sepx,-0.5*\sepy)}]
  \coordinate[label = below:$A$] (A) at (-3,-1.5);
  \coordinate[label = above:$B$] (B) at (-3,1.5);
  \coordinate[label = above:$C$] (C) at (3,1.5);
  \coordinate[label = below:$D$] (D) at (3,-1.5);
  \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
  \tkzLabelSegment[left](A,B){$3$};
  \tkzLabelSegment[above](B,C){$6$};
\end{scope}
%2
\begin{scope}[shift={(1.5*\sepx,-0.5*\sepy)}]
  \coordinate[label = below:$A$] (A) at (-1.5,-1.5);
  \coordinate[label = above:$B$] (B) at (-1.5,1.5);
  \coordinate[label = above:$C$] (C) at (1.5,1.5);
  \coordinate[label = below:$D$] (D) at (1.5,-1.5);
  \draw[ultra thick] (A) -- (B) -- (C) -- (D) -- cycle;
  \tkzMarkSegment[mark = |](A,B);
  \tkzMarkSegment[mark = |](B,C);
  \node at (0,0){$P=36$};
\end{scope}
%3
\begin{scope}[shift={(0.5*\sepx,-1.5*\sepy)}]
  \draw[ultra thick] (0,0) circle (2);
\end{scope}
\end{tikzpicture}
\end{figure}

\lipsum[2][1-3]
\end{document}

在此处输入图片描述

相关内容