6

I am trying to output a wide table with a caption using the standalone package.

When I do the following without a caption, I get nice output:

\documentclass{standalone}

\usepackage{caption}
\usepackage{booktabs}

\begin{document}
%\minipage{0.9\textwidth}
\begin{tabular}{llllllllll}
\toprule
  & \multicolumn{3}{c}{Model 1}
  & \multicolumn{3}{c}{Model 2}
  & \multicolumn{3}{c}{Model 3}
\\
    \cmidrule(r){2-4}
    \cmidrule(r){5-7}
    \cmidrule(r){8-10}
%
  Variable
    & Coefficient & Std Error & $p$-value
    & Coefficient & Std Error & $p$-value
    & Coefficient & Std Error & $p$-value
\\
\midrule
  Brand1:$\log p_t$
    & -3.44 & 0.226 & 2e-16***
    & -3.39 & 0.227 & 2e-16***
    & -3.27 & 0.231 & 2e-16***
\\
  Brand2:$\log p_t$
    & -2.67 & 0.250 & 2e-16***
    & -2.62 & 0.248 & 2e-16***
    & -2.61 & 0.248 & 2e-16***
\\
  Brand3:$\log p_t$
    & -4.45 & 0.413 & 2e-16***
    & -4.50 & 0.425 & 2e-16***
    & -4.43 & 0.427 & 2e-16***
\\
  Brand4:$\log p_t$
    & -2.34 & 0.607 & 1e-4***
    & -2.32 & 0.601 & 1e-4***
    & -2.38 & 0.599 & 9e-5***
\\
  Brand5:$\log p_t$
    & -3.92 & 0.536 & 2e-12***
    & -3.90 & 0.532 & 2e-12***
    & -3.86 & 0.530 & 2e-12***
\\[5pt]
  Brand1:$\log p_{t-1}$
    & & &
    & 0.435 & 0.227 & 0.056.
    & 0.518 & 0.229 & 0.024*
\\
  Brand2:$\log p_{t-1}$
    & & &
    & 0.226 & 0.248 & 0.362
    & 0.256 & 0.248 & 0.302
\\
  Brand3:$\log p_{t-1}$
    & & &
    & 1.024 & 0.410 & 0.012*
    & 1.078 & 0.423 & 0.011*
\\
  Brand4:$\log p_{t-1}$
    & & &
    & 0.547 & 0.602 & 0.364
    & 0.543 & 0.598 & 0.364
\\
  Brand5:$\log p_{t-1}$
    & & &
    & 0.151 & 0.532 & 0.777
    & 0.183 & 0.531 & 0.731
\\[5pt]
  Brand1:$\log p_{t-2}$
    & & &
    & & &
    & 0.465 & 0.231 & 0.045*
\\
  Brand2:$\log p_{t-2}$
    & & &
    & & &
    & 0.241 & 0.248 & 0.332
\\
  Brand3:$\log p_{t-2}$
    & & &
    & & &
    & 0.067 & 0.413 & 0.870
\\
  Brand4:$\log p_{t-2}$
    & & &
    & & &
    & -0.508 & 0.599 & 0.397
\\
  Brand5:$\log p_{t-2}$
    & & &
    & & &
    & 0.047 & 0.530 & 0.979
\\[5pt]
  Brand1:MAPE
    & \multicolumn{3}{c}{0.146}
    & \multicolumn{3}{c}{0.131}
    & \multicolumn{3}{c}{0.114}
\\
  Brand2:MAPE
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.109}
\\
  Brand3:MAPE
    & \multicolumn{3}{c}{0.108}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
  Brand4:MAPE
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.194}
\\
  Brand5:MAPE
    & \multicolumn{3}{c}{0.110}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
\bottomrule
\end{tabular}
%\captionof{table}{Regression results for 5 brands of coffee in a single store.}
%\endminipage
\end{document}

Output of code without caption

Based on Errors using standalone package to create a table, I try to use a minipage environment and the caption package to include a caption. The code and the output follows below:

\documentclass{standalone}

\usepackage{caption}
\usepackage{booktabs}

\begin{document}
\minipage{0.9\textwidth}
\begin{tabular}{llllllllll}
\toprule
  & \multicolumn{3}{c}{Model 1}
  & \multicolumn{3}{c}{Model 2}
  & \multicolumn{3}{c}{Model 3}
\\
    \cmidrule(r){2-4}
    \cmidrule(r){5-7}
    \cmidrule(r){8-10}
%
  Variable
    & Coefficient & Std Error & $p$-value
    & Coefficient & Std Error & $p$-value
    & Coefficient & Std Error & $p$-value
\\
\midrule
  Brand1:$\log p_t$
    & -3.44 & 0.226 & 2e-16***
    & -3.39 & 0.227 & 2e-16***
    & -3.27 & 0.231 & 2e-16***
\\
  Brand2:$\log p_t$
    & -2.67 & 0.250 & 2e-16***
    & -2.62 & 0.248 & 2e-16***
    & -2.61 & 0.248 & 2e-16***
\\
  Brand3:$\log p_t$
    & -4.45 & 0.413 & 2e-16***
    & -4.50 & 0.425 & 2e-16***
    & -4.43 & 0.427 & 2e-16***
\\
  Brand4:$\log p_t$
    & -2.34 & 0.607 & 1e-4***
    & -2.32 & 0.601 & 1e-4***
    & -2.38 & 0.599 & 9e-5***
\\
  Brand5:$\log p_t$
    & -3.92 & 0.536 & 2e-12***
    & -3.90 & 0.532 & 2e-12***
    & -3.86 & 0.530 & 2e-12***
\\[5pt]
  Brand1:$\log p_{t-1}$
    & & &
    & 0.435 & 0.227 & 0.056.
    & 0.518 & 0.229 & 0.024*
\\
  Brand2:$\log p_{t-1}$
    & & &
    & 0.226 & 0.248 & 0.362
    & 0.256 & 0.248 & 0.302
\\
  Brand3:$\log p_{t-1}$
    & & &
    & 1.024 & 0.410 & 0.012*
    & 1.078 & 0.423 & 0.011*
\\
  Brand4:$\log p_{t-1}$
    & & &
    & 0.547 & 0.602 & 0.364
    & 0.543 & 0.598 & 0.364
\\
  Brand5:$\log p_{t-1}$
    & & &
    & 0.151 & 0.532 & 0.777
    & 0.183 & 0.531 & 0.731
\\[5pt]
  Brand1:$\log p_{t-2}$
    & & &
    & & &
    & 0.465 & 0.231 & 0.045*
\\
  Brand2:$\log p_{t-2}$
    & & &
    & & &
    & 0.241 & 0.248 & 0.332
\\
  Brand3:$\log p_{t-2}$
    & & &
    & & &
    & 0.067 & 0.413 & 0.870
\\
  Brand4:$\log p_{t-2}$
    & & &
    & & &
    & -0.508 & 0.599 & 0.397
\\
  Brand5:$\log p_{t-2}$
    & & &
    & & &
    & 0.047 & 0.530 & 0.979
\\[5pt]
  Brand1:MAPE
    & \multicolumn{3}{c}{0.146}
    & \multicolumn{3}{c}{0.131}
    & \multicolumn{3}{c}{0.114}
\\
  Brand2:MAPE
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.109}
\\
  Brand3:MAPE
    & \multicolumn{3}{c}{0.108}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
  Brand4:MAPE
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.194}
\\
  Brand5:MAPE
    & \multicolumn{3}{c}{0.110}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
\bottomrule
\end{tabular}
\captionof{table}{Regression results for 5 brands of coffee in a single store.}
\endminipage
\end{document}

Output of code with caption

What should I do so that the output is not cut off?

  • 2
    Your table is too wide for \textwidth. In the first case, it goes into the margin, but your viewer can still see it. Inside the minipage, the extra gets truncated. Set the minipage width to 1.7\textwidth and you'll see the table reappear. – Steven B. Segletes Oct 24 '13 at 2:49
3

In your code, the problem arises because TeX tries to use the same font size (viz., \normalsize) for the tabular environment and the caption material. Because you're using the fairly narrow default value of \textwidth and, moreover, are using only 90% of that amount for the minipage, the table is simply too wide to fit in the space available.

I suggest you do the following: (i) use narrower column headers, (ii) reduce the value of the \tabcolsep parameter (which governs the width of the intercolumn space), (iii) don't use any whitespace at the start and end of the table, as well as (iv) use the dcolumn pacakge to align the numbers in four of the six data columns on the decimal points. With these changes, you'll get a table that uses the same font size for the caption and the contents of the tabular environment -- and fits into the text block.

enter image description here

\documentclass{standalone}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{caption}
\newcolumntype{z}{D{.}{.}{2.3}}

\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}

\addtolength{\tabcolsep}{-0.5pt}

\begin{document}
\begin{minipage}{\textwidth}
\begin{tabular}{@{}lzzlzzlzzl@{}}
\toprule
  Variable
  & \multicolumn{3}{c}{Model 1}
  & \multicolumn{3}{c}{Model 2}
  & \multicolumn{3}{c@{}}{Model 3}
\\
    \cmidrule(lr){2-4}
    \cmidrule(lr){5-7}
    \cmidrule(l){8-10}
%
    & \mc{Coeff} & \mc{Std Err} & $p$-value
    & \mc{Coeff} & \mc{Std Err} & $p$-value
    & \mc{Coeff} & \mc{Std Err} & $p$-value\\
\midrule
  Brand1:$\log p_t$
    & -3.44 & 0.226 & 2e-16***
    & -3.39 & 0.227 & 2e-16***
    & -3.27 & 0.231 & 2e-16***
\\
  Brand2:$\log p_t$
    & -2.67 & 0.250 & 2e-16***
    & -2.62 & 0.248 & 2e-16***
    & -2.61 & 0.248 & 2e-16***
\\
  Brand3:$\log p_t$
    & -4.45 & 0.413 & 2e-16***
    & -4.50 & 0.425 & 2e-16***
    & -4.43 & 0.427 & 2e-16***
\\
  Brand4:$\log p_t$
    & -2.34 & 0.607 & 1e-4***
    & -2.32 & 0.601 & 1e-4***
    & -2.38 & 0.599 & 9e-5***
\\
  Brand5:$\log p_t$
    & -3.92 & 0.536 & 2e-12***
    & -3.90 & 0.532 & 2e-12***
    & -3.86 & 0.530 & 2e-12***
\\[5pt]
  Brand1:$\log p_{t-1}$
    & & &
    & 0.435 & 0.227 & 0.056.
    & 0.518 & 0.229 & 0.024*
\\
  Brand2:$\log p_{t-1}$
    & & &
    & 0.226 & 0.248 & 0.362
    & 0.256 & 0.248 & 0.302
\\
  Brand3:$\log p_{t-1}$
    & & &
    & 1.024 & 0.410 & 0.012*
    & 1.078 & 0.423 & 0.011*
\\
  Brand4:$\log p_{t-1}$
    & & &
    & 0.547 & 0.602 & 0.364
    & 0.543 & 0.598 & 0.364
\\
  Brand5:$\log p_{t-1}$
    & & &
    & 0.151 & 0.532 & 0.777
    & 0.183 & 0.531 & 0.731
\\[5pt]
  Brand1:$\log p_{t-2}$
    & & &
    & & &
    & 0.465 & 0.231 & 0.045*
\\
  Brand2:$\log p_{t-2}$
    & & &
    & & &
    & 0.241 & 0.248 & 0.332
\\
  Brand3:$\log p_{t-2}$
    & & &
    & & &
    & 0.067 & 0.413 & 0.870
\\
  Brand4:$\log p_{t-2}$
    & & &
    & & &
    & -0.508 & 0.599 & 0.397
\\
  Brand5:$\log p_{t-2}$
    & & &
    & & &
    & 0.047 & 0.530 & 0.979
\\[5pt]
  Brand1:MAPE
    & \multicolumn{3}{c}{0.146}
    & \multicolumn{3}{c}{0.131}
    & \multicolumn{3}{c}{0.114}
\\
  Brand2:MAPE
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.111}
    & \multicolumn{3}{c}{0.109}
\\
  Brand3:MAPE
    & \multicolumn{3}{c}{0.108}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
  Brand4:MAPE
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.192}
    & \multicolumn{3}{c}{0.194}
\\
  Brand5:MAPE
    & \multicolumn{3}{c}{0.110}
    & \multicolumn{3}{c}{0.103}
    & \multicolumn{3}{c}{0.099}
\\
\bottomrule
\end{tabular}
\captionof{table}{Regression results for 5 brands of coffee in a single store.}
\end{minipage}
\end{document}
  • This works for this example so I am accepting it. However, supposing that my table were really too wide, if it say had additional models, and it would not be possible to fit in the available space, is there a way to make the available space wider? – I Like to Code Oct 25 '13 at 1:01
  • @ILiketoCode - thanks! If the table were even wider, one could proceed by choosing a smaller font size via a \small or \footnotesize instruction or via a \resizebox command. There are quite a few examples on TeX.SE of just such operations. – Mico Oct 25 '13 at 3:10
  • Thank you for your reply. So it is not possible to use the geometry package or any other method to increase the width of the standalone document? – I Like to Code Oct 25 '13 at 12:33
  • @ILiketoCode - It is definitely possible to use a package such as geometry to define a very wide text block. An overriding issue is this: What do you want to convey to your reader(s)? The table above already contains ten columns; what are your readers supposed to take away from seeing a table that has, say, 16, 19, or 25 columns? Would they maybe be better off if you created two (or three, depending on how many models you have and need to report on) separate tables, each containing no more than ten columns? – Mico Oct 25 '13 at 17:07
3

I would break this into two parts.

(1) I would put the table in its own file.

(2) I would import the table using \includegraphics

Call the file for your table mytable.tex

\documentclass{standalone}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{llllllllll}
    \toprule
      & \multicolumn{3}{c}{Model 1}
      & \multicolumn{3}{c}{Model 2}
      & \multicolumn{3}{c}{Model 3}
    \\
        \cmidrule(r){2-4}
        \cmidrule(r){5-7}
        \cmidrule(r){8-10}
    %
      Variable
        & Coefficient & Std Error & $p$-value
        & Coefficient & Std Error & $p$-value
        & Coefficient & Std Error & $p$-value
    \\
    \midrule
      Brand1:$\log p_t$
        & -3.44 & 0.226 & 2e-16***
        & -3.39 & 0.227 & 2e-16***
        & -3.27 & 0.231 & 2e-16***
    \\
      Brand2:$\log p_t$
        & -2.67 & 0.250 & 2e-16***
        & -2.62 & 0.248 & 2e-16***
        & -2.61 & 0.248 & 2e-16***
    \\
      Brand3:$\log p_t$
        & -4.45 & 0.413 & 2e-16***
        & -4.50 & 0.425 & 2e-16***
        & -4.43 & 0.427 & 2e-16***
    \\
      Brand4:$\log p_t$
        & -2.34 & 0.607 & 1e-4***
        & -2.32 & 0.601 & 1e-4***
        & -2.38 & 0.599 & 9e-5***
    \\
      Brand5:$\log p_t$
        & -3.92 & 0.536 & 2e-12***
        & -3.90 & 0.532 & 2e-12***
        & -3.86 & 0.530 & 2e-12***
    \\[5pt]
      Brand1:$\log p_{t-1}$
        & & &
        & 0.435 & 0.227 & 0.056.
        & 0.518 & 0.229 & 0.024*
    \\
      Brand2:$\log p_{t-1}$
        & & &
        & 0.226 & 0.248 & 0.362
        & 0.256 & 0.248 & 0.302
    \\
      Brand3:$\log p_{t-1}$
        & & &
        & 1.024 & 0.410 & 0.012*
        & 1.078 & 0.423 & 0.011*
    \\
      Brand4:$\log p_{t-1}$
        & & &
        & 0.547 & 0.602 & 0.364
        & 0.543 & 0.598 & 0.364
    \\
      Brand5:$\log p_{t-1}$
        & & &
        & 0.151 & 0.532 & 0.777
        & 0.183 & 0.531 & 0.731
    \\[5pt]
      Brand1:$\log p_{t-2}$
        & & &
        & & &
        & 0.465 & 0.231 & 0.045*
    \\
      Brand2:$\log p_{t-2}$
        & & &
        & & &
        & 0.241 & 0.248 & 0.332
    \\
      Brand3:$\log p_{t-2}$
        & & &
        & & &
        & 0.067 & 0.413 & 0.870
    \\
      Brand4:$\log p_{t-2}$
        & & &
        & & &
        & -0.508 & 0.599 & 0.397
    \\
      Brand5:$\log p_{t-2}$
        & & &
        & & &
        & 0.047 & 0.530 & 0.979
    \\[5pt]
      Brand1:MAPE
        & \multicolumn{3}{c}{0.146}
        & \multicolumn{3}{c}{0.131}
        & \multicolumn{3}{c}{0.114}
    \\
      Brand2:MAPE
        & \multicolumn{3}{c}{0.111}
        & \multicolumn{3}{c}{0.111}
        & \multicolumn{3}{c}{0.109}
    \\
      Brand3:MAPE
        & \multicolumn{3}{c}{0.108}
        & \multicolumn{3}{c}{0.103}
        & \multicolumn{3}{c}{0.099}
    \\
      Brand4:MAPE
        & \multicolumn{3}{c}{0.192}
        & \multicolumn{3}{c}{0.192}
        & \multicolumn{3}{c}{0.194}
    \\
      Brand5:MAPE
        & \multicolumn{3}{c}{0.110}
        & \multicolumn{3}{c}{0.103}
        & \multicolumn{3}{c}{0.099}
    \\
    \bottomrule
\end{tabular}
\end{document}

Then create another document from which to import the image:

\documentclass{standalone}

\usepackage{caption}
\usepackage{booktabs}
\usepackage{graphicx}

\begin{document}
\begin{minipage}{0.9\textwidth}
  \includegraphics[width=\textwidth]{mytable}
\captionof{table}{Regression results for 5 brands of coffee in a single store.}
\end{minipage}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.