3

I'm getting an error when rendering the code below. If I change the column specification to lSSSSS, it works fine, which is really confusing.

\begin{table}
    \small
    \sisetup{group-digits=false, table-format=1.6, table-auto-round=true, table-number-alignment = left}
    \renewcommand{\arraystretch}{1.2}
    \centering
    \begin{tabular}{SSSSSS}\toprule
        \multicolumn{3}{l}{\bf Scenario} & \multicolumn{3}{l}{\bf Power/ Size *} \\
        \cmidrule(r){1-3}
        \cmidrule(l){4-6}
        {Effect Size ($\delta$)} & {Variance of Santa Returns ($\sigma_s^2$)} & {Variance of Non-Santa Returns ($\sigma_n^2$)} & {Student's t-test} & {Welch's t-test} & {Mann-Whitney U Test} \\\midrule
        \csvreader
        [late after line=\\]
        {../Results/table_results.csv}
        {"delta"=\diff, 
         "var.s"=\vars,
         "var.n"=\varn,
         "t.test"=\ttest, 
         "welch.t.test"=\welchttest,    
         "mwu.test"=\mwutest
        }
        {\diff & 
         \vars & 
         \varn & 
         \ttest & 
         \welchttest & 
         \mwutest
        }
        \midrule
        \multicolumn{6}{p{400pt}}{\small *If $\delta = 0$ these values represent the size of each test, otherwise they represent their power.} \\       
        \bottomrule
    \end{tabular}
    \caption{\label{tab:results}The power of the Student's t-test, Welch's t-test and the Mann-Whitney U test in various scenarios.}
\end{table}

If anybody knows what I've done wrong, I'd be really grateful if you could help me out.

4
  • 1
    Which error(s) do you have?
    – Bernard
    Nov 11, 2018 at 15:58
  • "Extra }, or forgotten $. late after line=\\"
    – Henry
    Nov 11, 2018 at 16:02
  • 3
    Please post a full compilable code. Your snippet has many non-standard commands.
    – Bernard
    Nov 11, 2018 at 16:09
  • 1
    With your current setup, the table is massively wider than the text block since you currently don't allow line breaks in the header cells. If switching from S to l for the first column makes a big difference, it's almost certainly because there are some non-numeric entries in the first column of the data file.
    – Mico
    Nov 11, 2018 at 16:49

1 Answer 1

3

Without access to your file ../Results/table_results.csv, it's not really possible to offer a definitive diagnosis of, let alone a cure for, whatever may be going on in the first column of the data file. However, given that you report that changing the column type of the first column from S to l "solves" the immediate problem, one can't help but suspect that there are some non-numeric data in the first column of the csv file and that these non-numeric data cannot be parsed successfully by the siunitx package.

A separate, serious problem with your table is that line breaks aren't allowed in the header cells. Therefore, the table is much wider than the text block. One way to fix this problem is to switch to a tabularx environment and to use the X column type only for the header cells, as is demonstrated in the following example.

I would also like to recommend that if you need to typeset table-related footnotes, you do so with the help of the threeparttable package and, in particular, that package's \tnote macro and tablenotes environment.

Since I don't have access to your csv file, I had to comment out the code that loads the data from an external file. I inserted a dummy row of numbers instead.

Oh, and don't overdo the bold-facing of header cells. In a well-designed table, it shouldn't be necessary to resort to this method of emphasis.

enter image description here

\documentclass{article}
\usepackage{siunitx,booktabs}
\usepackage{tabularx,ragged2e,caption}
\usepackage[flushleft]{threeparttable}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{@{}C@{}}{#1}}
\begin{document}
\begin{table}
\small
\captionsetup{skip=0.333\baselineskip,
              font=small}
\sisetup{group-digits=false, 
         table-format=1.6, 
         table-auto-round=true, 
         table-number-alignment = left
         }
\renewcommand{\arraystretch}{1.2}

\begin{threeparttable}
\caption{The power of Student's $t$-test, Welch's $t$-test, and the 
   Mann-Whitney U~test in various scenarios.}
\label{tab:results}

\begin{tabularx}{\textwidth}{@{} *{6}{S} @{}}
\toprule
\multicolumn{3}{@{}l}{%\bfseries 
   Scenario} & 
\multicolumn{3}{l@{}}{%\bfseries 
   Power\slash Size\tnote{*}} \\
\cmidrule(r){1-3} \cmidrule(l){4-6}
\mC{Effect Size \newline ($\delta$)} & 
\mC{Variance of Santa Returns ($\sigma_s^2$)} & 
\mC{Variance of Non-Santa Returns ($\sigma_n^2$)} & 
\mC{Student's $t$-test} & 
\mC{Welch's $t$-test} & 
\mC{Mann-Whitney U~Test} \\
\midrule
1.1 & 1.1 & 1.1 & 1.1 & 1.1 & 1.1 \\  % dummy entries
%%% I had to comment out the following lines:
%\csvreader[late after line=\\]
%   {../Results/table_results.csv}
%        {"delta"=\diff, 
%         "var.s"=\vars,
%         "var.n"=\varn,
%         "t.test"=\ttest, 
%         "welch.t.test"=\welchttest,    
%         "mwu.test"=\mwutest}
%   {\diff & 
%         \vars & 
%         \varn & 
%         \ttest & 
%         \welchttest & 
%         \mwutest}  
\bottomrule
\end{tabularx}

\smallskip
\begin{tablenotes}
\footnotesize
\item[*] If $\delta = 0$, these values represent the size of each test. 
  Otherwise, they represent their power.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
0

You must log in to answer this question.

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