1

So I am aware that this question has been asked and answered a few times, however I cannot get the existing solutions to work for me.

I have a latex table that is the output from Stata (statistical software) and I am loading it into my existing latex document using the \input{} command. The table is too big, and I need to scale it down.

My table file looks like this:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Linear Model, h=10}
\begin{tabular}{l*{5}{c}}
\hline\hline
                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}\\
                &\multicolumn{1}{c}{Corrupt Items}&\multicolumn{1}{c}{Corrupt Resources}&\multicolumn{1}{c}{Diversion Items}&\multicolumn{1}{c}{Fraud Items}&\multicolumn{1}{c}{Overinvoiced Items}\\
\hline
model               &                     &                     &                     &                     &                     \\
T                   &     -0.0226         &     -0.0194         &     -0.0389         &   0.0000768         &     -0.0226         \\
                &     (-0.99)         &     (-0.45)         &     (-1.31)         &      (0.00)         &     (-0.99)         \\
[1em]
R                   &     0.00247         &     0.00510         &     0.00379         &    -0.00140         &     0.00247         \\
                &      (0.78)         &      (0.86)         &      (0.94)         &     (-0.54)         &      (0.78)         \\
[1em]
R*T                 &    -0.00539         &     -0.0161\sym{*}  &    -0.00301         &    -0.00108         &    -0.00539         \\
                &     (-1.35)         &     (-2.13)         &     (-0.58)         &     (-0.32)         &     (-1.35)         \\
[1em]
Constant            &      0.0766\sym{***}&       0.105\sym{**} &      0.0381         &      0.0163         &      0.0766\sym{***}\\
                &      (4.45)         &      (3.26)         &      (1.71)         &      (1.14)         &      (4.45)         \\
\hline
sigma               &                     &                     &                     &                     &                     \\
Constant            &      0.0441\sym{***}&      0.0827\sym{***}&      0.0531\sym{***}&      0.0352\sym{***}&      0.0441\sym{***}\\
                &      (9.41)         &      (9.17)         &      (6.97)         &      (6.93)         &      (9.41)         \\
\hline
Observations        &          54         &          54         &          54         &          54         &          54         \\
\hline\hline
\multicolumn{6}{l}{\footnotesize All are tobit regressions, censored at 0}\\
\multicolumn{6}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}

And then as suggested by this page I attempt to call it and rescale it in this manner:

\documentclass{beamer}
\mode<presentation> {
\usetheme{Madrid}
}
\usepackage{graphicx} 
\usepackage{booktabs} 
\usepackage{graphics}
\usepackage{subcaption}
\usepackage{mwe}

\newlength{\tempwidth}

\begin{document}

\begin{frame}
\begin{table}
\let\center\empty
\let\endcenter\relax
\centering
\resizebox{.5\width}{!}{\input{tablefile.tex}}
\end{table}
\end{frame}

\end{document}

Yet, it is still throwing me errors, saying "Not in outer par mode". What is going on here?

8
  • 3
    You have two \begin{table}: one outside and one in the tablefile.tex. Apr 18, 2017 at 14:50
  • Also, \caption doesn't like being inside a box. Apr 18, 2017 at 15:16
  • If I just use \input{tablefile.tex} without any of the outer table or resizebox then it runs without error and fits on the page. Is this table really an example of the problem? how much smaller do you need it? Apr 18, 2017 at 15:24
  • The table looks like this and is much less than the width of the page. Apr 18, 2017 at 15:26
  • @DavidCarlisle I have removed most of the rows from the table to keep it simple. However, the problem is that the columns are too wide to stay on a single beamer slide. I took it out of the beamer class to keep the post simple, but perhaps that is part of the problem.
    – Alexander
    Apr 18, 2017 at 15:49

3 Answers 3

2

Your suggested code had table inside table and table inside resizebox, neither of which will work.

If you just input the table

\documentclass{beamer}
\mode<presentation> {
\usetheme{Madrid}
}
\usepackage{graphicx} 
\usepackage{booktabs} 
\usepackage{graphics}
\usepackage{subcaption}
\usepackage{mwe}

\newlength{\tempwidth}

\begin{document}

\begin{frame}
{\input{tablefile.tex}}


\end{frame}

\end{document}

then it is a bit too wide

Overfull \hbox (18.97734pt too wide) in paragraph at lines 4--17

If you want to shrink it without editing the generated file in any way probably the best hook is \centering. \small was enough for the original example, for the larger table in the edited example, you need \tiny, although I pity your audience if they try to read this much data on a slide:-)

\documentclass{beamer}
\mode<presentation> {
\usetheme{Madrid}
}
\usepackage{graphicx} 
\usepackage{booktabs} 
\usepackage{graphics}
\usepackage{subcaption}
\usepackage{mwe}

\newlength{\tempwidth}

\begin{document}

\begin{frame}
{
\let\oldcentering\centering
\renewcommand\centering{\tiny\oldcentering}
\input{tablefile.tex}}


\end{frame}

\end{document}

enter image description here

5
  • When I use the code above, my output still doesn't fit on the screen. However, I am issued a warning that says "LaTeX Font Warning: Font shape `OT1/cmss/m/n' in size <4> not available(Font) size <5> substituted on input line 22.", which I am guessing is the culprit. Is it likely that my version of Latex is too old and doesn't have the needed font?
    – Alexander
    Apr 18, 2017 at 19:58
  • @Alexander no I get that warning as well (ignore it:-) but the input files that you show make the output that I showed, do you mean you r real table was larger? Apr 18, 2017 at 20:00
  • @Alexander oh hang on you had changed the table when making it beamer, I'll rebuild, give me a minute.... Apr 18, 2017 at 20:01
  • @Alexander updated answer with the larger table. Apr 18, 2017 at 20:05
  • Perfect, it looks like that is working. Thanks very much for the help.
    – Alexander
    Apr 18, 2017 at 20:12
3

Instead of resizing the table yourself, you could tell beamer to shrink the whole frame. For example \begin{frame}[shrink=30] should be enough to accommodate your table.

\documentclass{beamer}
\mode<presentation> {
\usetheme{Madrid}
}
%\usepackage{graphicx} 
\usepackage{booktabs} 
%\usepackage{graphics}
\usepackage{subcaption}
%\usepackage{mwe}

\newlength{\tempwidth}

\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\begin{document}

\begin{frame}[shrink=30]
\begin{table}
\caption{Linear Model, h=10}
\begin{tabular}{l*{5}{c}}
    \toprule
    & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)}\\
    & \multicolumn{1}{c}{Corrupt Items} & \multicolumn{1}{c}{Corrupt Resources} & \multicolumn{1}{c}{Diversion Items} & \multicolumn{1}{c}{Fraud Items} & \multicolumn{1}{c}{Overinvoiced Items}\\
    \midrule
    model & & & & & \\
    T & -0.0226 & -0.0194 & -0.0389 & 0.0000768 & -0.0226 \\
    & (-0.99) & (-0.45) & (-1.31) & (0.00) & (-0.99) \\[1em]
    R & 0.00247 & 0.00510 & 0.00379 & -0.00140 & 0.00247 \\
    & (0.78) & (0.86) & (0.94) & (-0.54) & (0.78) \\[1em]
    R*T & -0.00539 & -0.0161\sym{*} & -0.00301 & -0.00108 & -0.00539 \\
    & (-1.35) & (-2.13) & (-0.58) & (-0.32) & (-1.35) \\[1em]
    Constant & 0.0766\sym{***} & 0.105\sym{**} & 0.0381 & 0.0163 & 0.0766\sym{***}\\
    & (4.45) & (3.26) & (1.71) & (1.14) & (4.45) \\
    \midrule
    sigma & & & & & \\
    Constant & 0.0441\sym{***} & 0.0827\sym{***} & 0.0531\sym{***} & 0.0352\sym{***} & 0.0441\sym{***}\\
    & (9.41) & (9.17) & (6.97) & (6.93) & (9.41) \\
    \midrule
    Observations&54 &54 &54 &54 &54 \\
    \bottomrule
    \multicolumn{6}{l}{\footnotesize All are tobit regressions, censored at 0}\\
    \multicolumn{6}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{frame}

\end{document}

enter image description here

0

If the table were in fact too wide, one could rescale it using the following kludge. The \begroup ... \egroup makes the changes local (especially \endtable). The minipage is needed for \caption, but you need to know the width of the tabular if you want the caption centered.

\documentclass[12pt, a4paper]{scrartcl}

\usepackage{graphicx}

\newlength{\tempwidth}

\begin{document}

\begin{table}
\bgroup
  \def\table[#1]{}% gobble [htbp]
  \let\endtable\relax
  \let\centering\relax
  \settowidth{\tempwidth}{\def\caption#1{}% width of tabular
    \input{tablefile.tex}}%
  \resizebox{\textwidth}{!}{\begin{minipage}{\tempwidth}%
    \input{tablefile.tex}
  \end{minipage}}%
\egroup
\end{table}

\end{document}

Here is a beamer version. The problem occurs when beamer tries to gather the contents of the frame environment into a macro (\test). The environ package had the same problem gathering it into \BODY. One can fix it by putting the contents of the frameinto a savebox outside the frame environment.

Note that with beamer, captions are not self centering.

\documentclass{beamer}
\mode<presentation> {
\usetheme{Madrid}
}
%\usepackage{graphicx} 
\usepackage{booktabs} 
%\usepackage{graphics}
\usepackage{subcaption}
%\usepackage{mwe}

\newlength{\tempwidth}
\newsavebox{\tempbox}

\begin{document}

\savebox{\tempbox}{%
  \expandafter\edef\csname @captype\endcsname{table}% table caption
  \def\table[#1]{}% gobble [htbp]
  \let\endtable\relax
  %\let\centering\relax
  \settowidth{\tempwidth}{\def\caption#1{}% gobble caption
    \input{tablefile}}% width of tabular
  \resizebox{\textwidth}{!}{\begin{minipage}{\tempwidth}%
    \input{tablefile}
  \end{minipage}}%
}

\begin{frame}
\frametitle{Test}
\usebox{\tempbox}
\end{frame}
\end{document}
4
  • Thank you John. This seems to be working great in the document class; however; I'm having trouble with it in beamer. Any idea why the difference?
    – Alexander
    Apr 18, 2017 at 16:01
  • I had no problem with beamer. Is your beamer version in the same folder as tablefile? Apr 18, 2017 at 16:09
  • Yea, its in the same folder. I've added my beamer code above in the original question.
    – Alexander
    Apr 18, 2017 at 16:36
  • Ah, I didn't use frame. Apr 18, 2017 at 21:56

You must log in to answer this question.

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