76

I have a bunch of LaTeX-output from Gnuplot which I would really like to leave alone. Is there an easy way of scaling an entire figure?

Something like

\includegraphics[scale=0.5]{...}

but just for the figure environment?

If it matters, I have

\begin{figure}
\input{plot.tex}
\end{figure}

and the output is from gnuplot used "set terminal latex" and so on.

0

3 Answers 3

98

You are looking for the macros

  • \resizebox{<h-length>}{<v-length>}{<content>} and
  • \scalebox{<h-scale>}[<v-scale>]{<content>}

from the graphics/graphicx packages (→ graphics manual, 4.3 “Scaling”, p. 3).

The \scalebox macro expects ratios like those you’d use in \includegraphics, you would be using

\begin{figure}
    \scalebox{.5}{\input{plot.tex}}
\end{figure}

or, if you rather want to resize the content to a fixed width (or height),

\begin{figure}
    \resizebox{.9\linewidth}{!}{\input{plot.tex}}
\end{figure}

where ! means that the content gets resized so that it keeps its aspect ratio.

There exist also a starred version of \resizebox and you can use the lengths \height, \width, \totalheight and \depth to refer to the original sizes of the content; meaning the factor .5 could be used with \resizebox, too:

\begin{figure}
    \resizebox{.5\totalheight}{!}{\input{plot.tex}}
\end{figure}
2
  • 20
    Is it possible to do something like this from outside of the figure environment?
    – jacobq
    Commented Oct 7, 2013 at 18:55
  • 1
    \scalebox also works with .pstex_t files exported from xfig (the .pstex_t file includes --with \includegraphics-- a .pstex file). \resizebox does not work.
    – kavadias
    Commented May 29, 2016 at 1:11
6

If you're using subfigures that are scaled and want non-subfigure plots to match the others' layout, you can use the subfigure code as well with just one plot:

\begin{figure}[t]
  \centering
  \begin{subfigure}[b]{0.95\textwidth}
     \include{plot.tex}
  \end{subfigure}
  \caption{
    My caption...
  }
  \label{fig:myPlot}
\end{figure}

(In my case, using the other suggested answer left some components of the plot not matching -- maybe axis labels or legend, I forget -- thus my hacky approach.)

1
  • 1
    ! LaTeX Error: Environment subfigure undefined. Commented Sep 4, 2021 at 16:54
4

Using ratio\textwidth can be an easier solution for resizing the figure.

\begin{figure}[!ht]
    \centering
    \includegraphics[width=0.45\textwidth]{figures.png}
    \caption{in 0.45, you can use any ratio that fits your single figure}
    \label{fig:label01}
\end{figure}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .