答案1
由于链接的示例仅适用于 TiKZ,因此这里有一个简单的方法可以将方格纸添加到任何元帖子图形。
这是使用以下源生成的,并经过编译lualatex
:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
input graphpaper
beginfig(1);
path xx, yy, ff;
xx = 42 left -- 377 right;
yy = 21 down -- 233 up;
ff = (20, 20) {right} .. (300, 200) {dir 10};
drawarrow xx;
drawarrow yy;
draw ff withcolor 2/3 red;
add_background_grid(1cm, 3/4 white);
add_background_grid(1mm, 7/8 white);
endfig;
\end{mplibcode}
\end{document}
该add_background_grid
宏定义如下:
vardef add_background_grid(expr s, c) =
save B, C;
path B; B = bbox currentpicture;
picture C; C = currentpicture;
currentpicture := nullpicture;
for x = s step s until floor xpart urcorner B:
draw (x, ceiling ypart llcorner B) -- (x, floor ypart urcorner B) withcolor c;
endfor
for x = 0 step -s until ceiling xpart llcorner B:
draw (x, ceiling ypart llcorner B) -- (x, floor ypart urcorner B) withcolor c;
endfor
for y = s step s until floor ypart urcorner B:
draw (ceiling xpart llcorner B, y) -- (floor xpart urcorner B, y) withcolor c;
endfor
for y = 0 step -s until ceiling ypart llcorner B:
draw (ceiling xpart llcorner B, y) -- (floor xpart urcorner B, y) withcolor c;
endfor
draw C;
enddef;
我已将其保存为graphpaper.mp
并使用input graphpaper
第一个示例顶部的行。
其工作原理是测量当前图片的边界框的大小;擦除当前图片;绘制网格(从原点开始);然后在顶部绘制原始图片的保存副本。