[pstricks] grid as background in an environment

Herbert Voss Herbert.Voss at alumni.TU-Berlin.DE
Sat Oct 11 09:59:41 CEST 2003


Martin Buchmann schrieb:

> I'm not sure if this is really bug free. I never did arithmetics in TeX 
> beforebut it is working for my minimal example.

it is bugfree, but I suppose that you'll get some more
problems. Here comes a slightly changed solution

Herbert


\documentclass[12pt]{article}
\usepackage{calc}
\usepackage{multido}
\usepackage{pstricks}
\makeatletter
\newdimen\xMax
\newdimen\yMax
\newcount\xLines
\newcount\yLines
\newdimen\dx
\newdimen\dy
\newcommand{\grid}[3][black]{{%
     \xMax=#3%
     \yMax=#2%
     \dx=5mm  \xLines=\xMax \divide\xLines by \dx%
     \dy=5mm  \yLines=\yMax \divide\yLines by \dy%
     \advance\xLines by 1%
     \advance\yLines by 1%
     \yMax=\dy \multiply\yMax by \yLines%
     \xMax=\dx \multiply\xMax by \xLines%
     \advance\xLines by 1%
     \advance\yLines by 1%
     \psset{unit=1pt, linecolor=#1}%
     \multido{\rA=0+\strip at pt\dx}{\xLines}{\psline(\rA,0)(\rA,\yMax)}%
     \multido{\rA=0+\strip at pt\dy}{\yLines}{\psline(0,\rA)(\xMax,\rA)}%
}}
\makeatother
\newsavebox{\gridbox}
\newenvironment{dogrid}[1][\linewidth]{%
   \begin{lrbox}{\gridbox}%
       \begin{minipage}{#1}%
}{%
       \end{minipage}%
   \end{lrbox}%
   \yMax=\dp\gridbox \advance\yMax by \ht\gridbox
   \noindent%
   \raisebox{-1.05\dp\gridbox}{\grid[yellow]{\yMax}{\wd\gridbox}}%
   \usebox{\gridbox}
   \vspace{0.5cm}
}

\begin{document}

\begin{dogrid}
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
\end{dogrid}

\begin{dogrid}[.5\linewidth]
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
     Test Test Test Test Test Test Test Test Test Test Test Test
\end{dogrid}

\end{document}




More information about the PSTricks mailing list