I am using PdfLaTeX (MiKTeX) called via R-Brew to dynamically populate and generate a LaTeX table. Use of R tables does not support all of the statistics, and is not flexible enough for the tables I need, hence the R>Brew>Sweave>LaTeX procedure. Everything works well, except I would like to have the numbers centered around the decimal point.
This is complicated by:
- significant p-values (<0.05) need to be bolded followed by an asterisk,
- significant p-values (<0.01) need to include a less-than "<" sign in front of them, the number bolded, and followed by an asterisk, and
- the p-values are unknown until after compile (dynamically populated).
This example table is what I have working now, and does not include centering the numbers about the decimal. I included the p-values in this table, but keep in mind the p-values are not actually there until compilation. There are too many tables to manually sift through, and they are much larger than the examples below.
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{booktabs}
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space,
justification=raggedright, singlelinecheck=off}
\usepackage{chngpage}
\usepackage{amsmath}
\usepackage{fp}
\begin{document}
\newcommand\pval[1]{
\FPifgt{#1}{0.009}
\FPiflt{#1}{0.05}
\textbf{#1}\text{*}%
\else
\FPiflt{#1}{0.01}
\textless\textbf{0.01}\text{*}%
\else
#1%
\fi
}
\begin{table}[tbp]
\centering
\caption{Table: Example table.}
\label{tab:my-table}
\begin{tabular}{@{}crccc@{}}
\toprule
\multicolumn{1}{c}{Case} & \multicolumn{1}{c}{Statistic} & \multicolumn{1}{c}{Run\_1} & \multicolumn{1}{c}{Run\_2} & \multicolumn{1}{c}{Run\_3} \\ \midrule
A & Mean & 4.53 & 5.67 & 2.46 \\
B & Mean & 5.38 & 5.83 & 3.94 \\
A-B & p-value & \pval{0.01} & \pval{0.09} & \pval{0.01} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
An example of the table above before values are injected and compilation.
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{booktabs}
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space,
justification=raggedright, singlelinecheck=off}
\usepackage{chngpage}
\usepackage{amsmath}
\usepackage{fp}
\begin{document}
\newcommand\pval[1]{
\FPifgt{#1}{0.009}
\FPiflt{#1}{0.05}
\textbf{#1}\text{*}%
\else
\FPiflt{#1}{0.01}
\textless\textbf{0.01}\text{*}%
\else
#1%
\fi
}
\begin{table}[tbp]
\centering
\caption{Table: Example table.}
\label{tab:my-table}
\begin{tabular}{@{}crccc@{}}
\toprule
\multicolumn{1}{c}{Case} & \multicolumn{1}{c}{Statistic} & \multicolumn{1}{c}{Run\_1} & \multicolumn{1}{c}{Run\_2} & \multicolumn{1}{c}{Run\_3} \\ \midrule
A & Mean & <%= stat1$A %> & <%= stat1$B %> & <%= stat1$C %> \\
B & Mean & <%= stat2$A %> & <%= stat2$B %> & <%= stat2$C %> \\
A-B & p-value & \pval{<%= stat3$A %>} & \pval{<%= stat3$B %>} & \pval{<%= stat3$C %>} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
Using dcolumn seems to work the best with what I have tried so far - it does not center the significant p-values correctly though. siunitx throws errors in the log files for every try I have attempted with it.