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