如何使用 tikz 在页面上绘制绝对定位的网格?
以下每一页都有问题。 某个地方是否存在舍入错误?
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\date{}
\title{}
\begin{document}
\thispagestyle{empty}
% wrong join on left, not closed on right
\begin{tikzpicture}[remember picture, overlay]
\draw[xshift=-1mm,yshift=-1mm,step=8.0mm,thin,black] ($(current page.south west) + (17mm, 17mm)$) grid ($(current page.south west) + (17mm,17mm) + (176mm,264mm)$);
\end{tikzpicture}
\pagebreak
\thispagestyle{empty}
% wrong join on left, not closed on right
\begin{tikzpicture}[remember picture, overlay]
\draw[xshift=0mm,yshift=0mm,step=8.0mm,thin,black] ($(current page.south west) + (17mm, 17mm)$) grid ($(current page.south west) + (17mm,17mm) + (176mm,264mm)$);
\end{tikzpicture}
\pagebreak
\thispagestyle{empty}
% wrong join on left, wrong join on right
\begin{tikzpicture}[remember picture, overlay]
\draw[xshift=0mm,yshift=0mm,step=8.0mm,thin,black] ($(current page.south west) + (17mm, 17mm)$) grid ($(current page.south west) + (17mm,17mm) + (177mm,265mm)$);
\end{tikzpicture}
\end{document}
答案1
这是一个完美的网格:
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\date{}
\title{}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay, thin]
\coordinate (o) at ($(current page.south west) + (17mm, 17mm)$);
\foreach \x in {0,...,22}
\draw ([xshift=8mm*\x]o) -- ++(0mm,8mm*33);
\foreach \y in {0,...,33}
\draw ([yshift=8mm*\y]o) -- ++(8mm*22,0mm);
\end{tikzpicture}
\end{document}
以下是TikZ-pgf 手册(第 14.8 节电网操作)第 154 页,关于这个问题有如下说明:
由于舍入误差,网格的“最后”几行可能会被省略。在这种情况下,您必须在角点上添加一个 epsilon
因此,当需要高精度时,您不应该依赖 TikZ 网格。这可能会在未来版本中改变(我希望!)。
编辑:
如果您坚持使用网格,可以采用以下手动修复方法(我不推荐):
\begin{tikzpicture}[remember picture, overlay]
\draw[step=8.0mm, thin,black] ($(current page.south west) + (17.29mm, 17.1mm)$) grid ($(current page.south west) + (193.30mm,281.11mm)$);
\end{tikzpicture}