如何在 TikZ 中对齐覆盖网格?

如何在 TikZ 中对齐覆盖网格?

在尝试调整这个答案鉴于 OP 对另一个问题的评论,我发现我无法直接对齐覆盖的网格,以便步骤从与网格相同的点开始。

这为什么不起作用以及应该如何做?

代码(减去我添加的错误)改编自Michael Goerz 的例子

% Minor adaptions from http://michaelgoerz.net/notes/printable-paper-with-latex-and-tikz.html
\documentclass[a4paper, 10pt]{article} % for A4 size paper
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\colorlet{dlines}{green!25!black}
\colorlet{llines}{green!25!gray}
\tikzset{
  dashed lines/.style={llines, very thin, densely dashed},
  strong lines/.style={dlines, very thin},
}

\begin{tikzpicture}[remember picture, overlay]
  \draw[style=dashed lines] (current page.south west) ++(5mm,8.5mm) coordinate (a) grid [step=10mm] ++(200mm,280mm) coordinate (b);
  \draw[style=strong lines] (a) rectangle (b);
  \draw[style=strong lines] (a) grid [step=20mm] (b);
\end{tikzpicture}

\end{document}

网格错位

答案1

在使用时,\draw (a) grid (b);您可以使用\draw[shift={(a)}] (0,0) grid (b);从左下角开始的网格。

\documentclass[a4paper, 10pt]{article} % for A4 size paper
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\colorlet{dlines}{green!25!black}
\colorlet{llines}{green!25!gray}
\tikzset{
  dashed lines/.style={llines, very thin, densely dashed},
  strong lines/.style={dlines, very thin},
}

\begin{tikzpicture}[remember picture, overlay]
  \draw[style=dashed lines, shift={(current page.south west)},shift={(5mm,8.5mm)}] (0,0) coordinate (a) grid [step=10mm] (200mm,280mm) coordinate (b);
  \draw[style=strong lines] (a) rectangle (b);
  \draw[style=strong lines, shift={(a)}] (0,0) grid [step=20mm] (b);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容