答案1
答案2
一个版本带有tabular
,另一个版本带有TikZ
,当然带有 的输出TikZ
比这种非常简单的方法要好得多tabular
。
\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{tabular}{|*{5}{C{0.2cm}|}}
\hline
& & & & \tabularnewline
\hline
& & C & & \multicolumn{1}{c}{} \tabularnewline
\cline{1-4}
& & & \multicolumn{1}{c}{} \tabularnewline
\cline{1-3}
& & & \multicolumn{2}{c}{} \tabularnewline
\cline{1-3}
& \multicolumn{4}{c}{} \tabularnewline
\cline{1-1}
\end{tabular}
\begin{tikzpicture}[scale=0.5, line width=1pt]
\draw (0,0) grid (5,1);
\draw (0,0) grid (4,-1);
\draw (0,-1) grid (3,-2);
\draw (0,-2) grid (3,-3);
\draw (0,-3) grid (1,-4);
\node[left] (A) at (3,-0.5) {C};
\end{tikzpicture}
\end{document}
答案3
一个非常简短的代码pstricks
:
\documentclass[12pt, margin=3pt]{standalone}
\usepackage{fourier}
\usepackage{pstricks, auto-pst-pdf}
\begin{document}
\begin{pspicture*}(-0.5,-0.5)(5.5,5.5)
\psclip{\pspolygon(0,0)(1,0)(1,1)(3,1)(3,3)(4,3)(4,4)(5,4)(5,5)(0,5)}
\psgrid[subgriddiv=0](0,0)(5,5)
\endpsclip
\rput(2.4,3.4){C}
\end{pspicture*}
\end{document}
答案4
网格的缺点是水平线和垂直线是独立绘制的。比较:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz[x=1em, y=1em]
\draw[ultra thick]
(0, 0) grid[step=1em] (1, 1)
(2, 0) -- (3, 0) -- (3, 1) -- (2, 1) -- cycle
;
\end{document}
问题网格中缺失的方块增加了此类角的数量。现在有七个而不是四个角。因此,示例首先将外线绘制为封闭多边形以获得正确的线连接。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz[x=1em, y=-1em]
\draw
% Border as closed polygon for better corners.
(0, 0) -- ++(0, 5) -- ++(1, 0) -- ++(0, -1) -- ++(2, 0)
-- ++(0, -2) -- ++(1, 0) -- ++(0, -1) -- ++(1, 0)
-- ++(0, -1) -- cycle
% Horizontal lines
(0, 1) -- ++(4, 0)
(0, 2) -- ++(3, 0)
(0, 3) -- ++(3, 0)
(0, 4) -- ++(1, 0)
% Vertical lines
(1, 0) -- ++(0, 4)
(2, 0) -- ++(0, 4)
(3, 0) -- ++(0, 2)
(4, 0) -- ++(0, 1)
% Cells
(2.5, 1.5) node {c}
;
\end{document}