# Resizing the whole figure

Each of my article figures is in a separate .tex file (in a figure environment and has \includegraphics) and I use \input to include each in my article. The .tex files were generated automatically using the MATLAB programs I wrote.

I want to use the same .tex figures within my beamer presentation but they do not fit. How can I resize them? I tried:

\scalebox{.5}{\input{myfig.tex}}

without success.

This is an example myfig.tex

\begin{figure}
\centering
\begin{tabular}{c}
\includegraphics[scale=0.45]{myfig.eps}\\
Some text
\end{tabular}
\end{figure}

• You can use the option scale for \incudegraphics – Marco Daniel Feb 21 '17 at 16:15
• Please provide an MWE. the scalebox approach may be failing because of how you structured myfig.tex, we need to see a bit more of your approach to help you (but not too much otherwise it's difficult to cut through the noise) – Bordaigorl Feb 21 '17 at 16:25
• It's probably best to generate a pdf file for each figure (using the standalone document class) and then you can use \includegraphics with specified width to scale them to your liking. – JPi Feb 21 '17 at 18:20
• Well, you can't \scalebox a figure environment. But we still need some more info I think. Do you set the width key for \includegraphics explicitly in your .tex files? – Torbjørn T. Mar 4 '17 at 21:49
• @TorbjørnT. No width key. I included an example in my updated question. – Seeda Apr 12 '17 at 4:17

Try this version of \scalefiginput[<scale>]{<file>}:

\documentclass{article}

\usepackage{graphicx}

\usepackage{filecontents}
\begin{filecontents*}{myfig.tex}
\begin{figure}
\centering
\begin{tabular}{c}
\includegraphics[scale=0.45]{example-image} \\
Some text
\end{tabular}
\end{figure}
\end{filecontents*}

\let\oldincludegraphics\includegraphics
\newcommand{\scalefiginput}[2][1]{%
% Update \includegraphics to scale its argument
\renewcommand{\includegraphics}[2][]{\scalebox{#1}{\oldincludegraphics[##1]{##2}}}%
\input{#2}% Input figure
% Restore \includegraphics
\let\includegraphics\oldincludegraphics
}
\begin{document}

\input{myfig.tex}

\scalefiginput{myfig.tex}

\scalefiginput[.5]{myfig.tex}

\end{document}


The macro updates the way \includegraphics functions, changing it into a \scalebox{<scale>}{\includegraphics[..]{...}} version just for the inclusion of the <file>.

The <scale> is optional (defaulting to 1). You can also make it mandatory, if needed.

If you wish to scale everything (image and text), the following should do the trick:

\documentclass{article}

\usepackage{graphicx,environ}

\usepackage{filecontents}
\begin{filecontents*}{myfig.tex}
\begin{figure}
\centering
\begin{tabular}{c}
\includegraphics[scale=0.45]{example-image} \\
Some text
\end{tabular}
\end{figure}
\end{filecontents*}

\let\oldtabular\tabular
\let\endoldtabular\endtabular
\newcommand{\scalefiginput}[2][1]{{%
\RenewEnviron{tabular}[1]{%
\scalebox{#1}{\begin{oldtabular}{##1}
\BODY
\end{oldtabular}}}%
\input{#2}%
}}

\begin{document}

\input{myfig.tex}

\scalefiginput{myfig.tex}

\scalefiginput[.5]{myfig.tex}

\end{document}


The idea is to redefine the tabular environment so you can capture its entire contents and scale it to your liking.

• Thank you. I can use your solution to some extent. Your solution does not rescale the text underneath though. Any ideas? – Seeda Apr 30 '17 at 1:29
• @Seeda: That's a bizarre request. However, see the updated answer. – Werner Apr 30 '17 at 3:29
• I defined a scalefiginput and a scaletabinput. Can they both used together since includegraphics is within the tabular environment? Mine fails. – Seeda May 1 '17 at 13:19