答案1
如果你使坐标不是步长精确的倍数,你可以得到这种效果:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (.75,.75) grid (3.75,3.75);
\end{tikzpicture}
\end{document}
答案2
如果你喜欢一些更奇特的东西,你也可以尝试一下:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray,path fading=south] (.99,.75) grid (3.5,1);
\draw[step=0.5cm,color=gray,path fading=north] (.99,3.5) grid (3.5,3.75);
\draw[step=0.5cm,color=gray,path fading=west] (.75,.99) grid (1,3.5);
\draw[step=0.5cm,color=gray,path fading=east] (3.5,.99) grid (3.75,3.5);
\draw[step=0.5cm,color=gray] (1,1) grid (3.5,3.5);
\end{tikzpicture}
\end{document}
答案3
我需要同样的东西,但网格单元格中也有一些东西,我也想让它们淡出。这个解决方案可能不如其他解决方案优雅,但允许这种淡出。
它只是将褪色的矩形放在边缘上,使它们逐渐变成白色。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm] (0.1,0.1) grid (3.9,3.9);
% Some letters to demonstrate fading
\node at (0.25,0.25) {F};
\node at (0.75,0.75) {A};
\node at (1.25,0.25) {D};
\node at (1.75,0.75) {E};
\begin{scope}[transparency group]
% Left edge
\fill[path fading=east, color=white] (0,0) rectangle (1,4);
% Bottom edge
\fill[path fading=north, color=white] (0,0) rectangle (4,1);
% Right edge
\fill[path fading=west, color=white] (3,0) rectangle (4,4);
% Top edge
\fill[path fading=south, color=white] (0,3) rectangle (4,4);
\end{scope}
\end{tikzpicture}
\end{document}
答案4
借助 PSTricks,
\documentclass{article}
\usepackage{pstricks,multido}
\begin{document}
\begin{pspicture}(-4.5,-4.5)(4.5,4.5)
\multido{\ix=-4+1}{9}
{
\psline(\ix,4.5)(\ix,-4.5)
\psline(4.5,\ix)(-4.5,\ix)
}
\end{pspicture}
\end{document}