LaTeX PSTricks template

A LaTeX PSTricks template for a document whose figures are drawn in PostScript: a function plot, a node diagram, a construction and transparent fills.

First page of the PSTricks figures template

Open in LaTeX.to Download all files (zip)

Files:
main.tex

Download main.tex

% !TeX program = latex
\documentclass[11pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[margin=25mm]{geometry}
\usepackage{lmodern}
% [H] below keeps each figure where it is written instead of letting it float.
\usepackage{float}
% PSTricks draws in PostScript, so this file compiles with the LaTeX engine.
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{pst-node}
\usepackage{pst-grad}

% Three lines to change: title, author, date.
\title{Figures Drawn in PostScript}
\author{Your Name}
\date{\today}

\begin{document}
\maketitle

\section{Introduction}
Every figure in this document is PSTricks source written next to the text it
belongs to, so it uses the same fonts and the same math as the body and there
is no image file to keep in sync. Figure~\ref{fig:plot} is a function plot,
Figure~\ref{fig:nodes} a diagram of named boxes, Figure~\ref{fig:circle} a
construction on a circle, and Figure~\ref{fig:fills} a set of fills you can
see through. Copy the one closest to what you need and change the numbers.

\section{A function plot}
\verb|\psaxes| draws the axes, the ticks and their labels, and \verb|\psplot|
evaluates a formula written in PostScript. The formula \texttt{x 90 mul sin}
reads as: take \texttt{x}, multiply it by 90, take the sine, so one unit on
the axis is a quarter turn and the curve runs over two full turns.

\begin{figure}[H]
\centering
\begin{pspicture}(-0.9,-1.7)(10.4,1.7)
% Dx=90 labels the x axis in degrees; dx=1 puts a tick every unit. The axes
% cross at (0,-1), under the curves, so no label lands on a curve.
\psaxes[Ox=0,Oy=-1,Dx=90,dx=1,Dy=1,dy=1,linewidth=0.6pt]{->}(0,-1)(-0.6,-1)(8.7,1.5)
\psline[linecolor=lightgray,linewidth=0.6pt](0,0)(8.4,0)
% \psaxes prints no 0 on a y axis, so that one label is set by hand.
\rput[r](-0.18,0){0}
% One \psplot per curve: colour, style, then the range and the formula.
\psplot[linecolor=blue,linewidth=1.2pt,plotpoints=400]{0}{8}{x 90 mul sin}
\psplot[linecolor=red,linewidth=1.2pt,linestyle=dashed,plotpoints=400]{0}{8}{x 90 mul cos}
\psplot[linecolor=darkgray,linewidth=1pt,linestyle=dotted,plotpoints=400]{0}{8}{x 90 mul sin 2.71828 x 0.4 mul neg exp mul}
\rput[l](8.9,1.1){\small\color{blue}$\sin\theta$}
\rput[l](8.9,0.55){\small\color{red}$\cos\theta$}
\rput[l](8.9,0){\small\color{darkgray}damped}
\end{pspicture}
\caption{Sine, cosine and a damped sine over two turns, plotted by
\texttt{pst-plot}.}
\label{fig:plot}
\end{figure}

\section{Boxes and connections}
A box becomes a node when it is wrapped in \verb|\rnode|, and the connection
commands join two nodes by name, so moving a box moves its arrows with it.
\verb|\ncline| draws a straight connection, \verb|\ncarc| a curved one, and
\verb|\naput| sets a label on the side of the line it follows.

\begin{figure}[H]
\centering
\begin{pspicture}(0,-0.4)(11,4)
% One line per box: the position, the node name, then the text.
\rput(1.5,2.8){\rnode{outline}{\psframebox[fillstyle=solid,fillcolor=blue!12]{Outline}}}
\rput(5.5,2.8){\rnode{draft}{\psframebox[fillstyle=solid,fillcolor=blue!12]{Draft}}}
\rput(9.4,2.8){\rnode{review}{\psframebox[fillstyle=solid,fillcolor=blue!12]{Review}}}
\rput(5.5,0.3){\rnode{final}{\psframebox[fillstyle=solid,fillcolor=green!20,framearc=0.3]{Final PDF}}}
% One line per connection, from node name to node name.
\ncline{->}{outline}{draft}\naput{\small write}
\ncline{->}{draft}{review}\naput{\small send}
\ncarc[arcangle=-40,linestyle=dashed,linecolor=gray]{->}{review}{draft}\nbput{\small revise}
\ncline{->}{review}{final}\naput{\small accept}
\nccurve[angleA=-90,angleB=180,linecolor=blue]{->}{outline}{final}\ncput*{\small short cut}
\end{pspicture}
\caption{Four named boxes and the connections between them, drawn by
\texttt{pst-node}.}
\label{fig:nodes}
\end{figure}

\section{A construction}
Circles, straight lines and arcs take coordinates in centimetres, and
\verb|\rput| places text at a point. The angle at $C$ is drawn with
\verb|\psarc|, which takes a centre, a radius and the two angles it runs
between; it comes out square because $AB$ is a diameter.

\begin{figure}[H]
\centering
\begin{pspicture}(-2.9,-2.6)(2.9,2.9)
% A dotted background grid. Delete this line for a plain figure.
\psgrid[subgriddiv=0,griddots=10,gridlabels=0pt,gridcolor=lightgray](-2,-2)(2,2)
\pscircle[linewidth=1pt](0,0){2}
% The triangle: A and B on the diameter, C on the circle at 50 degrees.
\psline[linewidth=1pt,linecolor=blue](-2,0)(2,0)
\psline[linewidth=1pt,linecolor=blue](-2,0)(1.286,1.532)(2,0)
\psline[linestyle=dashed,linecolor=gray](0,0)(1.286,1.532)
\psarc[linewidth=0.8pt,linecolor=red](1.286,1.532){0.45}{205}{295}
\psdots[dotsize=4pt](-2,0)(2,0)(1.286,1.532)(0,0)
\rput[r](-2.2,0){$A$}
\rput[l](2.2,0){$B$}
\rput[b](1.35,1.72){$C$}
\rput[t](-0.05,-0.15){$O$}
\rput(0.45,0.95){\small $r$}
\end{pspicture}
\caption{Every angle standing on a diameter is a right angle.}
\label{fig:circle}
\end{figure}

\section{Fills you can see through}
\texttt{fillstyle=solid} with a \texttt{fillcolor} fills a shape, and
\texttt{opacity} lets what is under it show through, so overlapping shapes mix
instead of hiding each other. \texttt{fillstyle=gradient} fades one colour
into another between \texttt{gradbegin} and \texttt{gradend}.

\begin{figure}[H]
\centering
\begin{pspicture}(0,0)(12,4)
\psframe[fillstyle=gradient,gradbegin=blue,gradend=white,gradangle=45,linewidth=0.4pt](0.2,0.4)(3,3.6)
% opacity runs from 0 (invisible) to 1 (solid).
\pscircle[fillstyle=solid,fillcolor=red,opacity=0.5,linewidth=0.4pt](5.2,2.5){1.1}
\pscircle[fillstyle=solid,fillcolor=blue,opacity=0.5,linewidth=0.4pt](6.4,2.5){1.1}
\pscircle[fillstyle=solid,fillcolor=green,opacity=0.5,linewidth=0.4pt](5.8,1.5){1.1}
\rput{25}(9.7,2.6){\psellipse[fillstyle=solid,fillcolor=orange,opacity=0.65,linewidth=0.4pt](0,0)(1.7,0.8)}
\psbezier[linewidth=1.2pt,linecolor=violet]{->}(8.1,0.4)(9.2,1.6)(10.6,0)(11.6,1.2)
\end{pspicture}
\caption{A gradient, three circles at half opacity and a curve.}
\label{fig:fills}
\end{figure}

\end{document}

How to use this template

Everything runs in your browser: nothing to install, no login, no compile timeout.

How to add a figure of your own

Every picture sits in a figure environment, so a new one gets a number, a caption and a reference like the others.

How to change colours and line styles

The keys in square brackets after a drawing command set how the shape looks.

How to choose the engine

PSTricks draws in PostScript, so it needs an engine that runs a PostScript step.

More templates: TikZ figures and all templates.