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?
- 95,681
- 297
3 Answers
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:-
- 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.
- Make sure the
\documentclass[...]{...}does not haveminimalorletteras the type, in which case, thefigureenvironment would not be recognized.
- 755
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.

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
graphicxand set the graphics path. Adjust the scale to meet your preference. - Compile it with
pdflatexorxelatex. You cannot uselatex-dvips-ps2pdfunless you haveEPSequivalent for each PDF output.
- 36,086
-
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
-
-
1@bogus: I updated the template in my answer, now it uses
standaloneclass you prefer. – kiss my armpit Sep 07 '13 at 02:57
If you have image files (EPS or PDF) you can include them with the graphicx package and \includegraphics{<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.
- 131
- 56,353
main_file.texusing Xelatex. – Prefect Jan 01 '23 at 18:27