0
votes

I would like to remove unnecessary margins (gray part in the figure below) in a PDF figure generated by epslatex (gnuplot).

Following are scripts and commands to create the figure.

set term epslatex standalone
set output "figure.tex"

set xlabel "\\LARGE $x$"
set ylabel "\\LARGE $y$"
set format x "\\Large{%.1f}"
set format y "\\Large{%.1f}"

set key left top Left
set size square

set xrange [0.0:1.0]
set yrange [0.0:1.0]

plot x     with lines dt 1 lw 5.0 lc rgb "red"   title "\\Large $y = x$",\
     x*x   with lines dt 2 lw 5.0 lc rgb "green" title "\\Large $y = x^2$",\
     x*x*x with lines dt 3 lw 5.0 lc rgb "blue"  title "\\Large $y = x^3$"

and commands

$ gnuplot sample.gp
$ pdflatex figure.tex

Instead of pdflatex, xelatex would also work. I would like to directly convert to PDF file.

It will be super good if we can remove these margins without too much effort (such as removing the margin manually one-by-one).

Thanks!

2
Can you share figure.tex? - samcarter_is_at_topanswers.xyz
epslatex is a very old driver. More recent drivers have other customization flags. For instance tightboundingbox in the lua tikz driver. Alternatively, why not use pdfcrop to fix the bounding box issue? - Alain Merigot
@samcarter: thank you, but "figure.tex" is just a long list describing the graph appearance since I am now using standalone mode - eng27
@AlainMerigot: thank you very much. I was not aware of tikz driver, but it seems really good! I will try to use it. pdfcrop worked, but the command cropped also some part of the figure.... it might work out if I specify the parameter manually. - eng27

2 Answers

2
votes

If you check help latex, it will tell you that default size is 5 x 3 inches. Since you set size square, there will be for sure an "unwanted" left and right margin.

What you can do to at least minimize the margins is to set the terminal size to square size as well, e.g. to 3 x 3 inches. However, keep in mind the graph size is square but x and y axes have tics and labels which require space depending on numbers and labels which might be different for x and y.

set term epslatex standalone size 3 in, 3 in

From help latex:

Syntax:

  set terminal {latex | emtex} {default | {courier|roman} {<fontsize>}}
               {size <XX>{unit}, <YY>{unit}} {rotate | norotate}

By default the plot will inherit font settings from the embedding document. You have the option of forcing either Courier (cmtt) or Roman (cmr) fonts instead. In this case you may also specify a fontsize. Unless your driver is capable of building fonts at any size (e.g. dvips), stick to the standard 10, 11 and 12 point sizes. ...

Maybe, there are LaTeX commands to crop the graph to its bounding box.

0
votes

Thanks to @AlainMarigot help, I change the system to Lua tikz with the option tightboundingbox. Looks good, but not exactly same as epslatex.