I am writing a math work, and I’d like to create a background which looks like a math notebook. Any idea how to do it ?
I found this solution, but I don’t know how to put it in a mini-page …omissis
Here’s one possible solution using the
background
package:<span class="kwd">\documentclass</span><span class="pun">{</span><span class="pln">article</span><span class="pun">}</span> <span class="kwd">\usepackage</span><span class="pun">{</span><span class="pln">background</span><span class="pun">}</span> <span class="kwd">\usepackage</span><span class="pun">{</span><span class="pln">lipsum</span><span class="pun">}</span> <span class="kwd">\newlength\mylen</span> <span class="kwd">\setlength\mylen</span><span class="pun">{</span><span class="kwd">\dimexpr\paperwidth</span><span class="pln">/40</span><span class="kwd">\relax</span><span class="pun">}</span> <span class="kwd">\SetBgScale</span><span class="pun">{</span><span class="pln">1</span><span class="pun">}</span> <span class="kwd">\SetBgAngle</span><span class="pun">{</span><span class="pln">0</span><span class="pun">}</span> <span class="kwd">\SetBgColor</span><span class="pun">{</span><span class="pln">blue!30</span><span class="pun">}</span> <span class="kwd">\SetBgContents</span><span class="pun">{</span><span class="kwd">\tikz</span><span class="pun">{</span><span class="kwd">\draw</span><span class="pun">[</span><span class="pln">step</span><span class="pun">=</span><span class="kwd">\mylen</span><span class="pun">]</span> <span class="pun">(</span><span class="pln">-.5</span><span class="kwd">\paperwidth</span><span class="pln">,-.5</span><span class="kwd">\paperheight</span><span class="pun">)</span><span class="pln"> grid </span><span class="pun">(</span><span class="pln">.5</span><span class="kwd">\paperwidth</span><span class="pln">,.5</span><span class="kwd">\paperheight</span><span class="pun">)</span><span class="pln">;</span><span class="pun">}}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">document</span><span class="pun">}</span> <span class="kwd">\lipsum</span><span class="pun">[</span><span class="pln">1-20</span><span class="pun">]</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">document</span><span class="pun">} </span>
And here’s an adaptation for TikZ of the code found here, for the case of
minipage
s; the main environment isgridmp
with an optional argument (the color for the rules) and a mandatory argument (the width of theminipage
):<span class="kwd">\documentclass</span><span class="pun">{</span><span class="pln">article</span><span class="pun">}</span> <span class="kwd">\usepackage</span><span class="pun">{</span><span class="pln">tikz</span><span class="pun">}</span> <span class="kwd">\usepackage</span><span class="pun">{</span><span class="pln">lipsum</span><span class="pun">}</span> <span class="kwd">\newcommand\MyGrid</span><span class="pun">[</span><span class="pln">3</span><span class="pun">]{</span><span class="com">%</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">tikzpicture</span><span class="pun">}[</span><span class="pln">remember picture,overlay</span><span class="pun">]</span> <span class="kwd">\draw</span><span class="pun">[</span><span class="pln">step</span><span class="pun">=</span><span class="lit">3mm</span><span class="pln">,color</span><span class="pun">=</span><span class="pln">#1</span><span class="pun">]</span> <span class="pun">(</span><span class="pln">0,0</span><span class="pun">)</span><span class="pln"> grid </span><span class="pun">(</span><span class="pln">#3,#2</span><span class="pun">)</span><span class="pln">; </span><span class="kwd">\draw</span><span class="pun">[</span><span class="pln">color</span><span class="pun">=</span><span class="pln">#1</span><span class="pun">]</span> <span class="pun">(</span><span class="pln">0,#2</span><span class="pun">)</span><span class="pln"> -- </span><span class="pun">(</span><span class="pln">#3,#2</span><span class="pun">)</span><span class="pln">; </span><span class="kwd">\end</span><span class="pun">{</span><span class="pln">tikzpicture</span><span class="pun">}</span><span class="com">%</span> <span class="pun">}</span> <span class="kwd">\newlength\MaxHt</span> <span class="kwd">\newsavebox\mybox</span> <span class="kwd">\newenvironment</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}[</span><span class="pln">2</span><span class="pun">][</span><span class="pln">lightgray</span><span class="pun">]</span> <span class="pun">{</span><span class="kwd">\def\mycolor</span><span class="pun">{</span><span class="pln">#1</span><span class="pun">}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">lrbox</span><span class="pun">}{</span><span class="kwd">\mybox</span><span class="pun">}</span><span class="com">%</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">minipage</span><span class="pun">}{</span><span class="pln">#2</span><span class="pun">}}</span> <span class="pun">{</span><span class="kwd">\end</span><span class="pun">{</span><span class="pln">minipage</span><span class="pun">}</span><span class="com">%</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">lrbox</span><span class="pun">}</span><span class="com">%</span> <span class="kwd">\setlength\MaxHt</span><span class="pun">{</span><span class="kwd">\dp\mybox</span><span class="pun">}</span><span class="kwd">\addtolength\MaxHt</span><span class="pun">{</span><span class="pln">1.1</span><span class="kwd">\ht\mybox</span><span class="pun">}</span> <span class="kwd">\noindent</span><span class="com">%</span> <span class="kwd">\raisebox</span><span class="pun">{</span><span class="pln">-</span><span class="kwd">\dp\mybox</span><span class="pun">}{</span><span class="kwd">\MyGrid</span><span class="pun">{</span><span class="kwd">\mycolor</span><span class="pun">}{</span><span class="kwd">\MaxHt</span><span class="pun">}{</span><span class="kwd">\wd\mybox</span><span class="pun">}}</span><span class="com">%</span> <span class="kwd">\usebox</span><span class="pun">{</span><span class="kwd">\mybox</span><span class="pun">}</span> <span class="kwd">\vspace</span><span class="pun">{</span><span class="lit">0.5cm</span><span class="pun">}}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">document</span><span class="pun">}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}{</span><span class="kwd">\linewidth</span><span class="pun">}</span> <span class="kwd">\lipsum</span><span class="pun">[</span><span class="pln">2</span><span class="pun">]</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}[</span><span class="pln">blue!30</span><span class="pun">]{</span><span class="kwd">\linewidth</span><span class="pun">}</span> <span class="kwd">\lipsum</span><span class="pun">[</span><span class="pln">2</span><span class="pun">]</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}</span> <span class="kwd">\begin</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}[</span><span class="pln">green!30</span><span class="pun">]{</span><span class="kwd">\linewidth</span><span class="pun">}</span> <span class="kwd">\lipsum</span><span class="pun">[</span><span class="pln">2</span><span class="pun">]</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">gridmp</span><span class="pun">}</span> <span class="kwd">\end</span><span class="pun">{</span><span class="pln">document</span><span class="pun">} </span>
Pages: 1 2