答案1
您也可以将其用于pgfplots
此。
代码
\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}
\begin{document}
\thispagestyle{empty}
\pgfplotsset{minor grid style = {dashed, Green}}
\pgfplotsset{major grid style = {solid, Green}}
\begin{figure}\centering
\begin{tikzpicture}[Green]
\begin{axis}[grid = both,
ticks = none,
minor tick num = 1,
xmin = 0,
ymin = 0,
xmax = 17,
ymax = 26,
width = 17cm,
height = 26cm,
scale only axis]
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
更新
如果您希望网格间隔 2cm,您可以做的一件事就是使用ytick
和xtick
选项,如下所示:
\begin{axis}[grid = both,
ticks = none,
minor tick num = 1,
xmin = 0,
ymin = 0,
xmax = 16,
ymax = 26,
xtick = {0, 2,..., 16},
ytick = {0, 2,..., 26},
width = 16cm,
height = 26cm,
scale only axis]
\end{axis}
答案2
我确信这是重复的,但这样更快:http://michaelgoerz.net/notes/printable-paper-with-latex-and-tikz.html并进行选择。
稍微修改一下 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,step=10mm] (current page.south west) grid +(210mm,297mm);
\draw[style=strong lines,step=20mm] (current page.south west) grid +(210mm,297mm);
\end{tikzpicture}
\end{document}
鉴于怪异grid
,稍微修改一下:
% Major 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]
\foreach \i in {5,25,...,205} \draw [strong lines] (current page.south west) ++(\i mm,8.5mm) -- ++(0,280mm);
\foreach \i in {15,35,...,195} \draw [dashed lines] (current page.south west) ++(\i mm,8.5mm) -- ++(0,280mm);
\foreach \i in {8.5,28.5,...,288.5} \draw [strong lines] (current page.south west) ++(5mm,\i mm) -- ++(200mm,0);
\foreach \i in {18.5,38.5,...,278.5} \draw [dashed lines] (current page.south west) ++(5mm,\i mm) -- ++(200mm,0);
\end{tikzpicture}
\end{document}
答案3
这是 tikz 中的一个数学游戏。下面再举一个例子:
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[a4paper,margin=1cm,showframe]{geometry}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\def\width{1.5cm}
\pgfmathsetlengthmacro{\offset}{\width+0.4cm}
\pgfmathsetlengthmacro{\rows}{floor(\textheight/\offset)-1}
\pgfmathsetlengthmacro{\cols}{floor(\textwidth/\width)-1}
\pgfmathsetlengthmacro{\dx}{(\textwidth-(1+\cols)*\width)/2}
\pgfmathsetlengthmacro{\dy}{(\textheight-(1+\rows)*\offset)/2}
\coordinate (O) at ([xshift=\dx,yshift=-\dy]current page text area.north west);
\foreach \i in {0,1,...,\cols}{
\foreach \j in {0,1,...,\rows} {
\draw[blue,thick] ([xshift=\i*\width,yshift=-\j*\offset]O) rectangle ++(\width,-\width);;
\draw[blue!40,dashed] ([xshift=\i*\width,yshift=-\width/2-\j*\offset]O) -- ++ (\width,0)
([xshift=\width/2+\i*\width,yshift=-\j*\offset]O) -- ++ (0,-\width);
}
}
\end{tikzpicture}
\end{document}
答案4
即可使用tikz
并tikzpagenodes
打包。
\documentclass{article}
\usepackage{tikzpagenodes}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\draw[blue,step=1cm] (current page text area.south west) grid (current page text area.north east);
\draw[blue!50,dashed,,step=5mm] (current page text area.south west) grid (current page text area.north east);
\end{tikzpicture}
\end{document}
如果您希望在每个页面上都使用此功能,请使用background
包。
除了grid
选择之外,还可以手动绘制这些。
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[a4paper,margin=2cm,showframe]{geometry}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
%% Vertical lines
\foreach \x in {0,0.1,...,1.1}{
\draw[blue] ([xshift=\x*\textwidth]current page text area.south west) --
([xshift=\x*\textwidth]current page text area.north west);
}
\foreach \x in {0.05,0.1,...,1}{
\draw[blue!40,dashed] ([xshift=\x*\textwidth]current page text area.south west) --
([xshift=\x*\textwidth]current page text area.north west);
}
%% horizontal lines
\foreach \x in {0,0.1,...,1.1}{
\draw[blue] ([yshift=\x*\textheight]current page text area.south west) --
([yshift=\x*\textheight]current page text area.south east);
}
\foreach \x in {0.05,0.1,...,1}{
\draw[blue!40,dashed] ([yshift=\x*\textheight]current page text area.south west) --
([yshift=\x*\textheight]current page text area.south east);
}
\end{tikzpicture}
\end{document}
此网格将精确占据可写区域。尝试更改边距并亲自查看。此外,可以通过更改循环中的序列来改变网格的密度\foreach
。