GeneralCreate a Consumer-Surplus-kind of diagram

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
aVirulence
Posts: 1
Joined: Fri Oct 26, 2007 2:11 pm

Create a Consumer-Surplus-kind of diagram

Post by aVirulence »

Hi, I'm trying to create a diagram/graph that depicts consumer surplus. Is there any way to do this in LateX?

If you don't know what I mean, here's an example:

http://en.wikipedia.org/wiki/Consumer_surplus

I don't need anything as fancy as that, I only need some linear lines and don't need color. What I basically need is something that makes a diagram with two axes, a couple of lines and I need to fill a part of the graph.

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: Create a Consumer-Surplus-kind of diagram

Post by balfonsi »

PSTricks can do about any kind of graphic. It's an interface between LaTeX and PostScript. Just be aware that you must take the 'LaTeX-> .dvi-> .ps' (actually .eps, as pdfLaTeX doesn't understand .eps files) way. Just a look at the documentation: you have commands such as \psaxes, \psline, \psplot and so on.

Regards,

B.A.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Create a Consumer-Surplus-kind of diagram

Post by gmedina »

You could use the package pstricks, but then you can't process your document using pdflatex directly (pstricks uses some commands that pdflatex does not recognize). (Edit: balfonsi already suggested this). You could also use the package pgf which unlike pstricks can produce either PostScript or PDF output.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: Create a Consumer-Surplus-kind of diagram

Post by balfonsi »

Actually, the method I recommend (but it depends on each individual case, of course) is to have separate (short) files for each figure you want. Then compile it to .dvi and convert it to .eps via the command:

dvips -E -o"mygraphicfile.eps"
(under some editors such as WinEdt under windows) this can be automated with a macro).
Finally, I convert the .eps file to a .pdf via eps2pdf (a special interface to ghostscript, which allows to easily convert several files at a time).

To have your figures in the main document, you just have to add the lines:
\beginfigure[!h]
\centering %% if you want to center, of course!
\includegraphics{mygraphicfile}%% no extension!
\end{figure}

This way: 1) you can re-use your file in other documents if necessary; 2) you can either compile with latex (the .eps file will be automatically chosen) or with pdflatex (the .pdf file will be) 3) pstricks has an advantage: there is a command '\psset{unit=...}'; using it, you can scale your figure, without scaling the text contained in it.

To obtain eventually an .eps figure, you must load the extensions pstricks.sty and pst-eps.sty; the description of you figure must be between the following commands:
\TeXtoEPS and \endTeXtoEPS. Here's a simple example, which draws two coordinates axes Ox,Oy:

\TeXtoEPS
\pspicture(-3,-3)(3,3)
\psaxes(0,0)(-3,-3)(3,3)%%the two axes intersect at (0,0), x and y go from -3 to 3
\uput[dl](0,0){$O}\uput[dl](3,0){$x$}\uput[dl](0,3){$y$}
\endpspicture
\endTeXtoEPS
Post Reply