Thursday, December 8, 2011

A Powerful Pstricks Tool ---- Psgrid

Making grid with pstricks is very easy. You can just include "\psgrid" in your pspicture environment (note that psgrid can also used outside pspicture environment), then a beautiful grid will be drawn, just like the following:

\documentclass{article}
\usepackage{pstricks}
\begin{document}
  \begin{pspicture}(5,4)
    \psgrid
  \end{pspicture}
\end{document}

Fig.1 The simplest usage of psgrid

Command "\psgrid" can be followed with three arguments, i.e., "\psgrid(x0,y0)(x1,y1)(x2,y2)". (x1,y1) and (x2,y2) are the opposing corner of the grid area. The dedault value of (x1,y1) is (0,0). If (x1,y1) and (x2,y2) are both not specified, in a pspicture environment the coordinate of the current pspicture will be used, and outside a pspicture environment (10,10) will be used. By default, the intervals are labeled. The horizontal labels will be placed at positions (*,y0) and the vertical labels will be placed at positions (x0,*). If (x0,y0) is omitted, (x1,y1) will be used.

The appearance of the grid can be changed if some parameters are applied."(sub)gridwidth","(sub)gridcolor" can be used to change the width and color of the main grid and sub grid. When (sub)griddots=num and num is a positive value , the (sub)grid lines are dotted with num dots per division. gridlabels and gridlabelcolor can used to control the size and color of the grid lables, and the default value of these two parameters is 10pt and black. If a positive int number(num) is set to parameter subgriddiv, then the main grid will be divided into num parts, and the default value is 5.

In the following example we will examine "\psgrid" in detail.

\documentclass{article}
\usepackage{pstricks}
\begin{document}
  \begin{pspicture}(9,9)
    \psgrid[gridcolor=red,subgridcolor=green]
      (1,5)(1,5)(4,8)
    \psgrid[gridcolor=blue,subgridcolor=yellow,
      gridlabels=5pt](6,6)(5,5)(8,8)
    \newrgbcolor{mycolor1}{0.5 0.3 0.3}
    \newrgbcolor{mycolor2}{0.3 0.5 0.5}
    \psgrid[gridcolor=mycolor1,
      subgridcolor=mycolor2,subgriddiv=2,
      subgridwidth=0.8pt,subgriddots=15,
      gridlabels=0](1,1)(4,4)
    \psgrid[griddots=10,subgriddots=3,
      gridlabelcolor=red](5,1)(8,4)
  \end{pspicture}
\end{document}

Fig.2 Psgrid with some options
Files Download: tex ps pdf

No comments:

Post a Comment

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.