对于以下内容,我想要获得10mm
方格纸左右边距的精确测量值,而不是20 mm
。
% https://tex.stackexchange.com/a/356984/2288
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage[
a4paper , right = 10mm , left = 10mm , includeheadfoot,
]{geometry}
\begin{document}
\pagestyle{empty}
\centering
% http://tex.stackexchange.com/a/15002/100384
\newcommand*{\getlength}[2]{%
% Convert to `cm` and round to two fractional digits:
\pgfmathsetmacro#1{round(0.0351459804*#2)}%
}
\vspace*{\fill}
\rotatebox{0}{
\begin{tikzpicture}
% a factor for measures, since pfplots produces slightly bigger images than defined
% in width/height. This can be used to adjust that problem manually
\pgfmathsetmacro{\factor}{0.9}% 0.9
% we will need some length in `cm`, without units, and rounded
\getlength{\yMax}{\factor*\textheight}
\getlength{\xMax}{\factor*\textwidth}
\begin{axis}[
set layers,
width=\factor\textwidth, height=\factor\textheight,
x = 1cm, y = 1cm,
xtick={0,1,...,\xMax},
ytick={0,1,...,\yMax},
minor xtick={0,0.1,0.2,...,\xMax},
minor ytick={0,0.1,0.2,...,\yMax},
tick style = {line width = 0.6pt, black!40!white},
minor tick style = {draw = none},
major tick style = {draw = none},
ticklabel style = {draw = none},
xticklabels=\empty, %xlabel = \empty,
yticklabels=\empty, %ylabel = \empty,
axis line style = {-latex},
grid = both,
minor grid style={line width=0.2pt, black!20!white},
major grid style={line width=0.6pt, black!60!white},
ymin=0, ymax=\yMax,
xmin=0, xmax=\xMax,
]
\begin{pgfonlayer}{axis grid}
\draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
\end{pgfonlayer}
\end{axis}
\end{tikzpicture}
}
\vspace*{\fill}
\end{document}
更新
编辑@JohnKormylo 的回答具有
\usepackage[
a4paper , right = 10mm , left = 10mm ,
top = 5 mm, headheight = 0 mm, headsep = 0 mm,
foot = 0 mm, bottom = 5 mm, showframe
]{geometry}
输出有两个问题:
1- 图纸在第二页,而第一页是空白的
2- 下边距小于指定的值5 mm
。
答案1
由于您的页面边距已有 1cm,我假设您希望方格纸填充文本区域(四舍五入到最接近的厘米)。
\vskip\topskip
每个页面开始时都会自动设置第一个基线。
showframe 选项仅用于调试/对齐。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage[
a4paper , right = 10mm , left = 10mm , includeheadfoot, showframe
]{geometry}
% http://tex.stackexchange.com/a/15002/100384
\newcommand*{\getlength}[2]{%
% Convert to `cm` and round to two fractional digits:
\pgfmathsetmacro#1{round(0.0351459804*#2)}%
}
\pagestyle{empty}
\begin{document}
\vspace*{\fill}\vskip-\topskip
\centering
\begin{tikzpicture}
% a factor for measures, since pfplots produces slightly bigger images than defined
% in width/height. This can be used to adjust that problem manually
\pgfmathsetmacro{\factor}{1.0}% 0.9
% we will need some length in `cm`, without units, and rounded
\getlength{\yMax}{\factor*\textheight}
\getlength{\xMax}{\factor*\textwidth}
\begin{axis}[
set layers,
width=\factor\textwidth, height=\factor\textheight,
scale only axis, name=border,
x = 1cm, y = 1cm,
xtick={0,1,...,\xMax},
ytick={0,1,...,\yMax},
minor xtick={0,0.1,0.2,...,\xMax},
minor ytick={0,0.1,0.2,...,\yMax},
tick style = {line width = 0.6pt, black!40!white},
minor tick style = {draw = none},
major tick style = {draw = none},
ticklabel style = {draw = none},
xticklabels=\empty, %xlabel = \empty,
yticklabels=\empty, %ylabel = \empty,
axis line style = {-latex},
grid = both,
minor grid style={line width=0.2pt, black!20!white},
major grid style={line width=0.6pt, black!60!white},
ymin=0, ymax=\yMax,
xmin=0, xmax=\xMax,
]
%\begin{pgfonlayer}{axis grid}% redundant
%\draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
%\end{pgfonlayer}
\end{axis}
\pgfresetboundingbox
\path (border.south west) (border.north east);
\draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}\vspace*{\fill}
\end{document}
此版本将网格放入保存框,然后将其放置在(current page.center)
使用处[remember picture, overlay]
。请确保运行两次。
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepackage{siunitx}
% http://tex.stackexchange.com/a/15002/100384
\newcommand*{\getlength}[2]{%
% Convert to `cm` and round to two fractional digits:
\pgfmathsetmacro#1{round(0.0351459804*#2)}%
}
\newsavebox{\gridbox}
\savebox\gridbox{\begin{tikzpicture}
\pgfmathsetmacro{\width}{\paperwidth-2cm}
\pgfmathsetmacro{\height}{\paperheight-2cm}
% we will need some length in `cm`, without units, and rounded
\getlength{\yMax}{\height}
\getlength{\xMax}{\width}
\begin{axis}[
set layers,
width=\width, height=\height,
scale only axis, name=border,
x = 1cm, y = 1cm,
xtick={0,1,...,\xMax},
ytick={0,1,...,\yMax},
minor xtick={0,0.1,0.2,...,\xMax},
minor ytick={0,0.1,0.2,...,\yMax},
tick style = {line width = 0.6pt, black!40!white},
minor tick style = {draw = none},
major tick style = {draw = none},
ticklabel style = {draw = none},
xticklabels=\empty, %xlabel = \empty,
yticklabels=\empty, %ylabel = \empty,
axis line style = {-latex},
grid = both,
minor grid style={line width=0.2pt, black!20!white},
major grid style={line width=0.6pt, black!60!white},
ymin=0, ymax=\yMax,
xmin=0, xmax=\xMax,
]
%\begin{pgfonlayer}{axis grid}% redundant
%\draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
%\end{pgfonlayer}
\end{axis}
\pgfresetboundingbox
\path (border.south west) (border.north east);
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.center) {\usebox\gridbox};
\end{tikzpicture}
\end{document}