10

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 ...

%%%
%%% quarre Kaestchenmuster
%%%
\def\quarre{%
\raisebox{\footskip}[0pt][0pt]{%

setlength{\unitlength}{.01\textwidth}% Einheit_1/100_Textweite
\begin{picture}(100,115)%
\color{black!10}%
\linethickness{0.075mm}%
\multiput(2,0)(2,0){49}{\line(0,1){110}}% 110-VER
\multiput(0,2)(0,2){54}{\line(1,0){100}}% 54-HOR
\color{black}%
\put(1,112.1){%
\begin{footnotesize}
\textsl{\textbf{Notizen}}
\end{footnotesize}}%
\end{picture}%
}%
}

would be great to combine it with this: Background image for minipage

oz123
  • 1,267

2 Answers2

13

Here's one possible solution using the background package:

\documentclass{article}
\usepackage{background}
\usepackage{lipsum}

\newlength\mylen
\setlength\mylen{\dimexpr\paperwidth/40\relax}

\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{blue!30}
\SetBgContents{\tikz{\draw[step=\mylen] (-.5\paperwidth,-.5\paperheight) grid (.5\paperwidth,.5\paperheight);}}

\begin{document}
\lipsum[1-20]
\end{document}

enter image description here

And here's an adaptation for TikZ of the code found here, for the case of minipages; the main environment is gridmp with an optional argument (the color for the rules) and a mandatory argument (the width of the minipage):

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\newcommand\MyGrid[3]{%
  \begin{tikzpicture}[remember picture,overlay]
    \draw[step=3mm,color=#1] (0,0) grid (#3,#2);
    \draw[color=#1] (0,#2) --  (#3,#2);
  \end{tikzpicture}%
}

\newlength\MaxHt
\newsavebox\mybox

\newenvironment{gridmp}[2][lightgray]
  {\def\mycolor{#1}
    \begin{lrbox}{\mybox}%
      \begin{minipage}{#2}}
  {\end{minipage}%
   \end{lrbox}%
   \setlength\MaxHt{\dp\mybox}\addtolength\MaxHt{1.1\ht\mybox}
   \noindent%
   \raisebox{-\dp\mybox}{\MyGrid{\mycolor}{\MaxHt}{\wd\mybox}}%
   \usebox{\mybox}
   \vspace{0.5cm}}

\begin{document}

\begin{gridmp}{\linewidth}
\lipsum[2]
\end{gridmp}

\begin{gridmp}[blue!30]{\linewidth}
\lipsum[2]
\end{gridmp}

\begin{gridmp}[green!30]{\linewidth}
\lipsum[2]
\end{gridmp}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • this is great, but i need to break my head how to make it work on debian squeeze, i am missing some latex packages (pause.sty, background.sty)... – oz123 Dec 05 '11 at 20:03
  • 1
    @Oz123 You can get background.dtx and background.ins from CTAN: http://www.ctan.org/tex-archive/macros/latex/contrib/background. Run latex background.ins to generate the .sty file that you can now place somewhere TeX can find it (your current working directory, for example). However, background uses PGF/TikZ, so if your system also lacks this package (or uses an old version), the problem will persists. Did you install your LaTeX system from the Debian repos? If so, it would be better to uninstall it and install TeX Live 2011 from TUG: http://www.tug.org/texlive/. – Gonzalo Medina Dec 05 '11 at 20:08
  • Hmm... I appreciate your hint, but I rather not mess around with texlive. It might break other codes I need. So, I'll wait for debian. Can I somehow combine my partial solution with that link ??? – oz123 Dec 05 '11 at 20:12
  • @Oz123: waiting for Debian repositories to get an updated LaTeX system could mean waiting for years (they still use TeX Live2009!). Anyway, download background.dtx and background.ins and proceed as I say in my previous comment, and keep your fingers crossed ;-) – Gonzalo Medina Dec 05 '11 at 20:21
  • I found this solution http://tug.org/PSTricks/Grids/overlay0.tex, but it won't compile , telling me "Undefined Control Sequence \end{dogrid}... any idea why? – oz123 Dec 05 '11 at 20:31
  • @Oz123: since it uses PS-Tricks, you can't compile using pdflatex; you have to use latex. or xelatex. – Gonzalo Medina Dec 05 '11 at 20:34
  • thanks, it does work. In parallel I also found a solution in a German website. I still wonder how to put a tikz picture in the background of a mini-page. But for now it's good enough. – oz123 Dec 05 '11 at 20:51
  • @Oz123: I'm designing a basic solution for minipages. However, I won't be able to post it right now. In 24 hours (or less, but I don't promise) I will update my answer. – Gonzalo Medina Dec 05 '11 at 22:43
  • @Oz123: I finally had time and designed and posted the solution for minipages; it should work with your current LaTeX installation. – Gonzalo Medina Dec 05 '11 at 23:47
  • thanks, this seems much nicer than the simple solution I found. – oz123 Dec 06 '11 at 11:44
4

From a German website a nice solution which does work with the old tex-live.

\documentclass[ngerman]{scrartcl}
\usepackage{babel}
\usepackage{tikz}
\newcommand{\karos}[2]{
 \begin{tikzpicture}
   \draw[step=0.5cm,color=gray] (0,0) grid (#1 cm ,#2 cm);
 \end{tikzpicture}
}
\begin{document}

\begin{minipage}{\textwidth}
 \karos{15}{4} % Karos der Breite 15cm und Höhe 4cm
\end{minipage}

%mini page ohne 
\karos{8}{3} % Karos der Breite 8cm und Höhe 3cm
\end{document}
oz123
  • 1,267