# Resize epslatex (gnuplot) graphics for Beamer slides

I have created some graphics in gnuplot using set terminal epslatex color and I rather liked them in my paper. However, once I tried to put them into Latex Beamer slides the way I put them into my paper,they where to big.

I reference the genrerated *.tex file like this:

\begin{figure}[htp]
\input{./path/to/*.tex}
\end{figure}


This file contains the labels and axises, which are in latex and make it look so nice. The file in turn references the actual graph (a pdf file, generated from the corresponding eps file, which gnuplot made) using an \includegraphics

Now I want to resize it to, say 90% of the free space on a slide. Setting \includegraphics[keepaspectratio=true,height=0.7\paperheight] alone won't do, since then the picture is smaller, but the labels are still the same.

How do I make both smaller: the stuff in the *.tex file and the included image? Bonuspoints, when I do not have to go back to gnuplot and regenerate the graphics from scratch.

• Have you tried \resizebox? You put all your stuff in a box and set its size to fit your slide – Lionel MANSUY Jan 21 '13 at 14:39
• I didn't know that one and it does exactly what I want it to. If you would post that as an answer I can 'accept' it. Or I could post it myself. – albifant Jan 21 '13 at 14:52

You could try the command \resizebox{width}{height}{box}. For exemple:

\resizebox{!}{.7\paperheight}{code of the box to resize}


will resize your box to 70% of the paper height, with respect to aspect ratio.

Note that if you provide both width and height, the aspect ratio will not be kept.

• To make it complete: \resizebox{!}{\textwidth}{\input{./path/to/*.tex}} is what I used. – albifant Jan 21 '13 at 15:21

The trouble with \resizebox is that also all labels & keys, which are inserted with \put, will be scaled too, and their size will be different from the main text size (which may be desirable or not). Furthermore, giving \input as argument to \resizebox will be problematic when the files generated by gnuplot are in a different folder (a trouble which, admittedly, can be avoided with \graphicspath).

I share the (partial) solution I've been using every once in a while:

\makeatletter
\newcommand*{\gnuplotinput}[2][1.0]{%
\begingroup
\let\@gnplt@input@includegraphics=\includegraphics
\def\includegraphics##1{\@gnplt@input@includegraphics[scale=#1]{#2}}%
\let\@gnplt@input@picture=\picture
\def\picture{\unitlength=#1\unitlength\relax\@gnplt@input@picture}%
\input{#2}%
\endgroup
}
\makeatother


This is based on the facts that

1. gnuplot uses a plain \includegraphics without optional parameter in the produced tex file, and
2. that all \put occur in a picture environment.

It also relies on the assumptions that

1. the tex and eps files generated by gnuplot are in the same folder,
2. the two files have the same name but for the extension (which is anyway the default, but who knows...), and
3. the common name of the files is passed as mandatory argument of \gnuplotinput without extension.

So if running gnuplot with epslatex terminal returns foo.tex and foo.eps, one can issue \gnuplotinput{foo}, or e.g. \gnuplotinput[0.5]{foo} to have the picture half its original size. (Of course this works best with scale factors relatively close to 1.)

The evil redefinitions of \includegraphics and \picture are contained in a group to make them local. At this point it is only possible to scale the whole figure by some global factor given as optional parameter; it might be possible to extend the syntax in order to pass explicit sizes (but, honestly, I never found it worth the time necessary to do it ;-)).

• Your script solved practically all my problem. I think it would be very interesting to add the possibility of fixed sizes, so you can use \linewidth as an argument and further standardize the graphics in the papers, for example. – marcelolpjunior Sep 27 '18 at 20:50
• I agree, it would be interesting, and I wrote it in the answer. But I still haven't found the time :-( – campa Sep 28 '18 at 7:40
• The solution you presented solved my problem for a long time, but after formatting my computer and reinstalling the programs, a number of errors appear when I try to use the lines of code you presented. Error Image: uploaddeimagens.com.br/imagens/… – marcelolpjunior Aug 19 at 18:19
• I searched for the command in the tex file and got no result, so Gnuplot, in the version I use (gnuplot 5.0 patchlevel 3) doesn't write this command in the tex file. Here's a link from a file produced with Gnuplot: docs.google.com/document/d/… – marcelolpjunior Sep 2 at 16:40
• In fact, even when I try to compile the GNUplot-generated tex file itself, it's a mistake! Maybe it's my program, I use TeXstudio. – marcelolpjunior Sep 2 at 17:06