3

I'm trying to create a standalone but the content won't fit inside.

enter image description here

I think \minipage{\textwidth} causes the issue. I know I can set e.g. \minipage{21cm} but I want to keep this dynamic since the table is created automatically from an R script. I also tried \minipage{\linewidth} but that didn't solve the problem either.

I have to adjust the script anyway to add the addition to \begin{tabular} and the additional \toprule which is not yet created automatically. It's quite a construction site right now. Therefore I also would appreciate if there would be a solution that doesn't change the code too much.

This is my code:

\documentclass[12pt]{standalone}
\usepackage{caption,booktabs,array}
\UseRawInputEncoding
\begin{document}
\minipage{\textwidth}
\begin{tabular}{@{\extracolsep{4pt}}>{\hangindent=1.5em\hangafter=1}p{2in}rrrrrrr}
\toprule
{} & \multicolumn{3}{c}{Treatment A} & \multicolumn{3}{c}{Treatment B}  & {}\\
\cmidrule{2-4}
\cmidrule{5-7}
 & Lorem & ipsum & dolor & sit & amets & consetetur & sadipscing \\
  \hline
luptatum blandit invidunt takimata & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sanctus eirmod sea labore & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  erats sea eirmod blandit & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sea iriure illum eum & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  zzril consetetur ipsum takimata & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  dolore hendrerit justo sit & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sit augue et Lorem & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  labore amets et dolores & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  ipsum justo autem vel & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  aliquyam velit luptatum Lorem & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
   \hline
\end{tabular}

\captionof{table}{My caption}
\endminipage
\end{document}
  • 1
    unrelated in this case but \minipage \endminipage should be \begin{minipage} \end{minipage} the implementation assumes the group from the environment is there. – David Carlisle Apr 20 at 11:43
  • You might also be interested in the varwidth package/ – John Kormylo Apr 20 at 15:13
5

enter image description here

\documentclass[12pt]{standalone}
\usepackage{caption,booktabs,array}
\UseRawInputEncoding
\begin{document}

\sbox0{%
\begin{tabular}{@{\extracolsep{4pt}}>{\hangindent=1.5em\hangafter=1}p{2in}rrrrrrr}
\toprule
{} & \multicolumn{3}{c}{Treatment A} & \multicolumn{3}{c}{Treatment B}  & {}\\
\cmidrule{2-4}
\cmidrule{5-7}
 & Lorem & ipsum & dolor & sit & amets & consetetur & sadipscing \\
  \hline
luptatum blandit invidunt takimata & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sanctus eirmod sea labore & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  erats sea eirmod blandit & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sea iriure illum eum & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  zzril consetetur ipsum takimata & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  dolore hendrerit justo sit & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  sit augue et Lorem & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  labore amets et dolores & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  ipsum justo autem vel & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
  aliquyam velit luptatum Lorem & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 & 9.99 \\ 
   \hline
\end{tabular}}

\begin{minipage}{\wd0}
\usebox0

\captionof{table}{My caption}
\end{minipage}



\end{document}
  • Nice and clean, thanks. The actual output will then look better than on the image. – jay.sf Apr 20 at 11:39
  • The line at the upper edge of the page, how could we omit this? – jay.sf Apr 20 at 15:42

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.