2

I am running into a problem while using the following code and I have tried every means to diagnose the problem (ie: commenting the contents out), but I have not been successful at finding the bug.

The code is as follows:

\documentclass{beamer}
\usepackage{booktabs,makecell,multirow,tabularx}
\usepackage{ragged2e}
\renewcommand\theadfont{\normalfont\bfseries}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mc[1]{\multicolumn{2}{c}{#1}}

\setlength\parindent{0pt}
%\usepackage[justification=centering]{caption}
\usepackage{siunitx}
\usepackage{tikz}

\usepackage{adjustbox}

\begin{document}

\begin{frame}[shrink=30]{Summary Statistics}          
    \vspace*{2em}          
    \setlength{\tabcolsep}{4pt} 


\begin{tabularx}{\textwidth}{@{} l L *{10}{S[table-format=3.3]} @{}}
    \toprule   
\thead[lc]{Benchmark} & \thead{(1,1)} & {\thead{(2,1)}} & {\thead{(3,1)}} & {\thead{(4,1)}} & {\thead{(5,1)}} & {\thead{(6,1)}} \
    & {\thead{(7,1)}} & \thead{(8,1)} & {\thead{(9,1)}} & {\thead{(10,1)}} & {\thead{(11,1)}} & {\thead{(12,1)}} \\
    \midrule

(1,1) & 0.00 & 0.01 & 0.02 & 0.02 & 0.03 & 0.03 & 0.05 & 0.02 & 0.01 & 0.01 & 0.09 & 0.00 \\


\bottomrule 
\end{tabularx} 

\end{frame}

The message I am getting is: "extra } or $", but I have checked everywhere and I don't see any problems. Hence, I would appreciate any help and advice.

5
  • Where is the compilable MWE?
    – Johannes_B
    Mar 11, 2016 at 7:43
  • Sorry edited to include all preambles Mar 11, 2016 at 7:45
  • I don't care about your preamble at all. You are missing the document environment. It is important to limit the error to a minimum.
    – Johannes_B
    Mar 11, 2016 at 7:47
  • Your defintion of the L column is faulty. X columns want to get a width.
    – Johannes_B
    Mar 11, 2016 at 7:47
  • @Johannes_B Ah, I see, sorry that was an error on my part as I missed it when copying. I have made the correct changes to define the document environment. How should you propose that I make the changes to redefine the columns ? Thank you Mar 11, 2016 at 7:49

3 Answers 3

3

If the objective is to make the width of the table equal to the width of the textblock, using a tabular* environment instead of a tabularx environment (with a single X-like column) seems preferable.

Incidentally, you may want to rethink using bold lettering for the header row. Sandwiching the header row between \toprule and \midrule is more than enough to give it all the visual prominence it requires; too much bold material quickly risks creating a vulgar look. The second table in the screenshot below demonstrates that (in my opinion) bold lettering is quite unnecessary.

enter image description here

\documentclass{beamer}
\usepackage{booktabs}

\begin{document}

\begin{frame}[shrink=30]{Summary Statistics}          
\vspace*{2em}          
% Let LaTeX determine amount of intercolumn whitespace
\setlength{\tabcolsep}{0pt} 

\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} *{12}{c}}
\toprule   
\textbf{Benchmark}& \textbf{(1,1)} 
& \textbf{(2,1)}  & \textbf{(3,1)} & \textbf{(4,1)} & \textbf{(5,1)}  
& \textbf{(6,1)}  & \textbf{(7,1)} & \textbf{(8,1)}  & \textbf{(9,1)} 
& \textbf{(10,1)} & \textbf{(11,1)} & \textbf{(12,1)} \\
\midrule
(1,1) & 0.00 & 0.01 & 0.02 & 0.02 & 0.03 & 0.03 & 0.05 & 0.02 & 0.01 & 0.01 & 0.09 & 0.00 \\
\bottomrule 
\end{tabular*} 

\vspace*{2cm}
\begin{tabular*}{\textwidth}{l 
         @{\extracolsep{\fill}} *{12}{c}}
\toprule   
{Benchmark}& (1,1) 
& (2,1)  & (3,1) & (4,1) & (5,1)  & (6,1) & (7,1) 
& (8,1)  & (9,1) & (10,1)& (11,1) & (12,1) \\
\midrule
(1,1) & 0.00 & 0.01 & 0.02 & 0.02 & 0.03 & 0.03 & 0.05 & 0.02 & 0.01 & 0.01 & 0.09 & 0.00 \\
\bottomrule 
\end{tabular*} 


\end{frame}
\end{document}
4

I use the package rccol which is easier to handle in this case. If you do not need three decimals then use R[.]{1}{2} instead

\documentclass{beamer}
\usepackage{booktabs,tabularx}
\usepackage{ragged2e}
\newcommand\MC[1]{\multicolumn{1}{c}{\bfseries#1}}
\usepackage{rccol}

\begin{document}

    \begin{frame}[shrink=30]{Summary Statistics}                  
        \bigskip\noindent\setlength{\tabcolsep}{2pt}
        \begin{tabular}{@{} l *{12}{R[.]{1}{3}} @{}}\toprule   
            Benchmark & \MC{(1,1)} & \MC{(2,1)} & \MC{(3,1)} & \MC{(4,1)} & \MC{(5,1)} & \MC{(6,1)} 
            & \MC{(7,1)} & \MC{(8,1)} & \MC{(9,1)} & \MC{(10,1)} & \MC{(11,1)} & \MC{(12,1)} \\\midrule             
            (1,1) & 0.00 & 0.01 & 0.02 & 0.02 & 0.03 & 0.03 & 0.05 & 0.02 & 0.01 & 0.01 & 0.09 & 0.00 \\                        
            \bottomrule 
        \end{tabular} 
    \end{frame}

 \end{document}

enter image description here

2

The actual error was missing multicolumn entries and declaring the wrong number of columns, however as the other answers have commented tabularx is the wrong environment to use for tables of numbers.

\documentclass{beamer}
\usepackage{booktabs,makecell,multirow,tabularx}
\usepackage{ragged2e}
\renewcommand\theadfont{\normalfont\bfseries}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mc[1]{\multicolumn{2}{c}{#1}}
\newcommand\m[1]{\multicolumn{1}{c}{#1}}

\setlength\parindent{0pt}

\usepackage{siunitx}


\begin{document}

\begin{frame}[shrink=30]{Summary Statistics}          
    \vspace*{2em}          
    \setlength{\tabcolsep}{4pt} 


\begin{tabularx}{\textwidth}{@{} l L *{11}{S[table-format=3.3]} @{}}
    \toprule   
\m{\thead[lc]{Benchmark}} & \m{\thead{(1,1)}} & \m{\thead{(2,1)}} & \m{\thead{(3,1)}} & \m{\thead{(4,1)}} & \m{\thead{(5,1)}} & \m{\thead{(6,1)}} 
    & \m{\thead{(7,1)}} & \m{\thead{(8,1)}} & \m{\thead{(9,1)}} & \m{\thead{(10,1)}} & \m{\thead{(11,1)}} & \m{\thead{(12,1)}} \\
    \midrule
(1,1) & 0.00 & 0.01 & 0.02 & 0.02 & 0.03 & 0.03 & 0.05 & 0.02 & 0.01 & 0.01 & 0.09 & 0.00 \\
\bottomrule 
\end{tabularx} 

\end{frame}

\end{document}

You must log in to answer this question.

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