Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use LaTeX regularly, and several times I have included .eps images. I am learning how to use PSTricks. I have used it to create .ps and .pdf files with images. There is plenty of free information on the web, but I haven't seen the answer to this question: how do you include the pictures that PSTricks produces in your LaTeX file?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

If you have image files (EPS or PDF) you can include them with the graphicx package and \includegraphic{<filename>}. latex needs an EPS and pdflatex a PDF file. If you put both in your folder and omit the suffix in the including macro the package decied which file to use automatically.

If you want to include the PSTricks code directly you may use the {pspicture}environment.

share|improve this answer
add comment

If you write each PSTricks diagram in a separate TeX input file and compile it with latex-dvips-ps2pdf (much faster) or xelatex (slower) to obtain a PDF output, you might need the PDF output without white spaces around it.

To obtain the tight PDF output, use the following template for each diagram you want to make.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid=true](-3,-3)(3,3)
% your drawing code goes here!
\end{pspicture}
\end{document}

It will be better if you put all your TeX input files for creating diagrams in a special folder outside other projects you have. This method will make your diagrams consumable to many projects easily. My directory structures look like below.

enter image description here

All my TeX input file for creating diagrams are placed in Diagrams. The PDF outputs associated with the input files are also in Diagrams for sure.

Another project, namely ProjectA, might use the diagrams you have made before. For example, let Main.tex be the input file in ProjectA folder. You can import the diagrams easily as follows.

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{../Diagrams/}}

\begin{document}
\begin{figure}
\centering
\includegraphics[scale=1.5]{Template}
\caption{This is my PSTricks template.}
\label{fig:Template}
\end{figure}
\end{document}

The important points are:

  • Load graphicx and set the graphics path. Adjust the scale to meet your preference.
  • Compile it with pdflatex or xelatex. You cannot use latex-dvips-ps2pdf unless you have EPS equivalent for each PDF output.
share|improve this answer
    
In case anyone is interested, I ended up using \documentclass[12pt]{standalone} in the file where the picture was drawn. It worked fine. –  bogus Mar 25 '12 at 19:41
    
@user20520: standalone internally uses preview package. –  Fifa Earth Cup 2014 Mar 25 '12 at 19:47
1  
@bogus: I updated the template in my answer, now it uses standalone class you prefer. –  Fifa Earth Cup 2014 Sep 7 '13 at 2:57
add comment

Say your PSTricks figure file looks like this:

\begin{pspicture}(0,-2.4)(7.72,2.4)
\psframe[linewidth=0.04,dimen=outer](7.72,2.4)(0.0,-2.4)
\end{pspicture} 

saved by the name picture_file.tex in the same folder as your main latex file.

In your latex main file, saved by the name main_file.tex, add

\usepackage{pstricks}    %for embedding pspicture.
\usepackage{graphicx}    %for figure environment.

in the preamble. (You can add additional things also as your needs.)

Now, the picture_file.tex can be included in the main_file.tex as:

%=========================
\begin{figure}[h]
\centering{
\resizebox{0.5\textwidth}{!}{\input{picture_file.tex}}}
\caption{your caption} \label{fig:figureone}
\end{figure}
%===========================

Only the main_file.tex needs be compiled.

Note:-

  1. If you use different fonts other than default ones, the fonts in figures will blend perfectly with the rest of the document by this method.
  2. Make sure the \documentclass[...]{...} does not have minimal or letter as the type, in which case, the figure environment would not be recognized.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.