Tuesday, November 29, 2011

Some basic graph objects in pstricks (1) ---- Dots

In this and the next few posts some basic graph objects will be introduced. And the first one to be talked is "dots".

Commands "\psdot[parameters](x1,y1)" and "\psdots[parameters](x1,y1)(x2,y2)...(xn,yn)" both draw dots on the canvas. The only difference is that the first one draw only one dot each time, while the second one can draw more than one.

What the dots looks like is depend on the parameters used. The most used parameters are "dotstyle","dotsize","linecolor","fillcolor". Dotstyle determine the style of the dots, for example "*" for a solid circle, "o" for a hollow circle, "x" for a x symbol,"square" for a square and so on. For a complete set of dotstyles you may refer to the official documents. The dotsize determine the size of the dots. The color of the dots is determined by linecolor. If the dots is with a hollow center, the center is colored with fillcolor except for dotstyle "diamond". There are also some other parameters, you can find them in the official document. And at last an example is shown below:

\documentclass{article}
\usepackage{pstricks}
\begin{document}
\begin{pspicture}(5,5)
  \psdot[linecolor=red,dotstyle=*,
    dotsize=24pt](1,4)
  \psdot[linecolor=blue,fillcolor=red,
  dotstyle=o,dotsize=24pt](1,3)
  \psdots[fillcolor=blue,dotstyle=square,
    dotsize=12pt](1,2)(2,2)(3,2)
  \psset{dotsize=24pt,linecolor=yellow}
  \psdots[dotstyle=x](2.5,4)
  \psdot[dotstyle=+](2.5,3)
\end{pspicture}
\end{document}   

The picture these code draw looks like this:
Fig.1 Draw dots using Pstricks

Files Download: tex ps pdf

Saturday, November 26, 2011

pspicture--an easy way to allocate space for pstricks elements

pspicture is a latex environment which can make the allocation of space for pstricks elements very easy. To show its utility, now we come to fix the second example in the previous posts.

\documentclass{article}
\usepackage{pstricks}
\begin{document}
Pstricks Hello world! Pstricks Hello world!

Hello,world! 
\begin{pspicture}(13ex,1ex) 
\rput(6ex,0.5ex){\color{red} Hello,world!} 
\end{pspicture}
Hello,World!

Pstricks Hello world! Pstricks Hello world!
\end{document}

Fig.1 pspicture environment
We see (Fig.1 pspicture environment) that this time the pstricks element "Hello,world!" has been placed in a right place. And some explanations on the pspicture environment is shown below:

1. Pspicture environment can followed by two coordinate argument, i.e., "\begin{pspicture}(x0,y0)(x1,y1)". The first one represents the lower left corner and the second one represents the upper right corner. If the first one is not specified, it is (0,0) by default.

2.There is a optional argument called "baseline"("\begin{pspicture}[baseline](x0,y0)(x1,y2)"). It sets the baseline fraction from the bottom. (Note that the value of baseline is not necessarily between 0 and 1.) If this argument is include but it is empty ([]), the baseline is set a horizontal line through the origin.

3.The pstricks element may extents out the space specified. But if you specify the environment like this "\begin{pspicture}*[baseline](x0,y0)(x1,y1)", the anything outside the specified area will be clipped.

Files download: tex ps pdf

Friday, November 25, 2011

Begin with Pstricks----Hello,world

It has be a tradition to give a "Hello, world" program first when a programming language is introduced. Pstricks is not a programming language (In fact, it is a set of macros that allow the inclusion of postscript drawings directly inside Tex or Latex code), but we will also begin it with "Hello, world".


\documentclass{article}
\usepackage{pstricks}
\begin{document}
  \rput(1,1){Hello,world} 
\end{document}

There are Some explanations on this example. "\rput(1,1){Hello,world}" draw text at position (1,1). The default coordinate Psstrick used is set up like this: the current point in Tex is used as the origin. The horizontal line through this point is the x-axes, and left is the positive direction. The vertical line through this point is the y-axes, and up direction is positive. The default unit is 1cm.

Save it as a file (for example, with file name Pstircks_hello_world.tex), then Tex compile it with "latex" command. To get a postscript file, "dvips" or other dvi to postscript program should be used. And to get a pdf file, a ps to pdf program is also needed. Note that dvi2pdf may not produce a correct pdf file.

At last the output file looks like this:

Fig.1 A simple Pstricks "Hello, world!" example

Files Download: tex ps pdf

Now we come to a a little more complex "Hello, world" example.

\documentclass{article}
\usepackage{pstricks}
\begin{document}
Pstricks Hello world! Pstricks Hello world! 

Hello,world! 
\rput(0,0){\color{red} Hello,world!} 
Hello,World!

Pstricks Hello world! Pstricks Hello world! 
\end{document}

This tex file will produce a ps or pdf file like this:
Fig.2 An advanced Pstricks "Hello, world!" example
Of course, This is not what we want. The pstricks element is overwritten. This is because Tex do not reserve any space for the pstricks element. So kept in mind that when you insert any pstricks element in, make sure you have leave proper space for it. And to solve it, Pstricks provide a very convenient method--pspicture environment. And it may be talked in the next posts.

Files Download: tex ps pdf
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.