1

I am new to Latex and have a problem understanding what is happening in my tables. I have used the code below to produce tables. I am using the \dcolumn to align values on the decimal sign, but this also seems to make some of the column names italic.

Is there a better way to align the values on the decimal, or should I edit what I have entered in the \dcolumn environment instead?

\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{d}{D{,}{.}{2}}  % define "d" column type
\newcommand\mc[1]{\multicolumn{1}{c}{2}} % handy shortcut macro
\usepackage{siunitx,booktabs,caption}
\begin{document}  

\begin{table}[htbp!]
\caption{\\Descriptive Statistics for Data Transformations}
\label{table:5:1}
\centering
\small
\begin{tabular}{ l *9 {d{2.6}} } 
{} & \multicolumn{2}{c}{Zone 1} & \multicolumn{2}{c}{Zone 2}
& \multicolumn{2}{c}{Zone 3} & \multicolumn{2}{c}{Zone 4}  \\
\toprule
{}  &  RMSE &   MAE &  RMSE &   MAE &  RMSE &   MAE &  RMSE & MAE \\
\midrule
$\hat{P}\textsubscript{d,h} | \textsubscript{d-1,h}$ & 14.34 &  6.76 & 14.35 &  6.78 & 29.64 & 14.53 & 34.16 & 17.97 \\
$\hat{P}\textsubscript{d,h} | \textsubscript{d-7,h}$ & 24.06 & 11.80 & 24.11 & 11.86 & 39.19 & 20.11 & 42.57 & 22.99$ \\
Standard & 20.69 &  9.00 & 20.69 &  9.01 & 30.27 & 15.27 & 34.43 & 18.46 \\
Custom & 21.44 & 10.10 & 21.47 & 10.13 & 34.45 & 17.41 & 38.21 & 20.47 \\
\bottomrule
\end{tabular}
\noalign{\vskip 1mm}   
\raggedright
\footnotesize{$\hat{P}\textsubscript{d,h} | \textsubscript{d-1,h}$ and $\hat{P}\textsubscript{d,h} | \textsubscript{d-7,h}$ are the naive forecasts from one and seven days before from equation (\ref{eq:4:1}). Standard and Custom are the naive forecasts from equation (\ref{eq:4:2}) and (\ref{eq:4:3}) respectively.}
\end{table}
\end{document}
1
  • 1
    I assume \newcommand\mc[1]{\multicolumn{1}{c}{2}} % handy shortcut macro is intended to be \newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro in which case it coud be used as \mc{MAE} as it is \mc{hello} discards the argument and typesets "2" Nov 5, 2022 at 13:33

2 Answers 2

1

dcolumn is math mode and aligned on decimal point, you do not want either of those for a heading so use a centered text mode cell

 & \multicolumn{1}{c}{MAE} &

Your example gives

! Package array Error:  Illegal pream-token (2.6): `c' used.

as

\newcolumntype{d}{D{,}{.}{2}}  % define "d" column type

should be

\newcolumntype{d}[1]{D{,}{.}{#1}}  % define "d" column type

so that d takes an argument as you have used it as d{2.6}

You get

! Extra }, or forgotten $

due to spurious $

and

! Misplaced \noalign.
l.26 \noalign

as you can not havee \noalign outside a table (and should not have it in a latex document at all)

\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{,}{.}{#1}}  % define "d" column type
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\usepackage{siunitx,booktabs,caption}
\begin{document}  

\begin{table}[htbp] % only ! for special cases
\caption{Descriptive Statistics for Data Transformations}
\label{table:dontusenumbers}
\centering
\small
\begin{tabular}{ l *9 {d{2.6}} } 
{} & \multicolumn{2}{c}{Zone 1} & \multicolumn{2}{c}{Zone 2}
& \multicolumn{2}{c}{Zone 3} & \multicolumn{2}{c}{Zone 4}  \\
\toprule
{}  &  \mc{RMSE} &   \mc{MAE} &  \mc{RMSE} &
\mc{MAE} &  \mc{RMSE} &   \mc{MAE} &  \mc{RMSE} & \mc{MAE} \\
\midrule
$\hat{P}\textsubscript{d,h} | \textsubscript{d-1,h}$ & 14.34 &  6.76 & 14.35 &  6.78 & 29.64 & 14.53 & 34.16 & 17.97 \\
$\hat{P}\textsubscript{d,h} | \textsubscript{d-7,h}$ & 24.06 & 11.80 & 24.11 & 11.86 & 39.19 & 20.11 & 42.57 & 22.99 \\
\mc{Standard} & 20.69 &  9.00 & 20.69 &  9.01 & 30.27 & 15.27 & 34.43 & 18.46 \\
\mc{Custom} & 21.44 & 10.10 & 21.47 & 10.13 & 34.45 & 17.41 & 38.21 & 20.47 \\
\bottomrule
\end{tabular}

\vspace{1mm}% really?
\raggedright
\footnotesize % no {..}
$\hat{P}\textsubscript{d,h} | \textsubscript{d-1,h}$ and $\hat{P}\textsubscript{d,h} | \textsubscript{d-7,h}$ are the naive forecasts from one and seven days before from equation (\ref{eq:aa}). Standard and Custom are the naive forecasts from equation (\ref{eq:bbb}) and (\ref{eq:someeqn}) respectively.
\end{table}
\end{document}
2
  • Thank you! How do you see these error codes? When I run the code in Overleaf I see nothing of these? Nov 6, 2022 at 11:13
  • @SimonRydstedt you see a red circle if there are errors then can view the log from the menu, or better on the green compile button choose "stop on first error" then it will show the log not a pdf if there is an error Nov 6, 2022 at 11:57
0

You can use siunitx features and tabular*.

\documentclass{article}
\usepackage{siunitx,booktabs,caption}

\captionsetup{labelsep=newline}

\begin{document}  

\begin{table}[htbp!]
\small

\caption{Descriptive Statistics for Data Transformations}
\label{table:5:1}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{8}{S[table-format=2.2]}
  @{}
} 
\toprule
{} & \multicolumn{2}{c}{Zone 1} & \multicolumn{2}{c}{Zone 2}
& \multicolumn{2}{c}{Zone 3} & \multicolumn{2}{c}{Zone 4}  \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
{} & {RMSE} & {MAE} & {RMSE} & {MAE} & {RMSE} & {MAE} & {RMSE} & {MAE} \\
\midrule
$\hat{P}_{d,h}|{}_{d-1,h}$ & 14.34 &  6.76 & 14.35 &  6.78 & 29.64 & 14.53 & 34.16 & 17.97 \\
$\hat{P}_{d,h}|{}_{d-7,h}$ & 24.06 & 11.80 & 24.11 & 11.86 & 39.19 & 20.11 & 42.57 & 22.99 \\
Standard                   & 20.69 &  9.00 & 20.69 &  9.01 & 30.27 & 15.27 & 34.43 & 18.46 \\
Custom                     & 21.44 & 10.10 & 21.47 & 10.13 & 34.45 & 17.41 & 38.21 & 20.47 \\
\bottomrule
\end{tabular*}

\smallskip

\footnotesize
$\hat{P}_{d,h}|{}_{d-1,h}$ and $\hat{P}_{d,h}|{}_{d-7,h}$ are the naive 
forecasts from one and seven days before from equation~(\ref{eq:4:1}). 
Standard and Custom are the naive forecasts from equations 
(\ref{eq:4:2})~and~(\ref{eq:4:3}) respectively.

\end{table}

\end{document}

Note that \textsubscript is for subscripts in text mode; in math mode you announce a subscript by _.

Your \noalign is out of place and you had a stray $ in the table body. Also caption features can be used instead of adding \\ at the beginning of the caption text, which would have bad effects in \listoftables.

enter image description here

Finally, if you are also using amsmath (and you should, since you have equations), it's better to use \eqref{label} instead of (\ref{label}).

You must log in to answer this question.

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