5

I would like to write a table in LaTeX using the following command:

\begin{table}[ht]
\centering
\begin{tabular}{c c c c c c c}
\hline
& ME & RMSE & MAE & MPE & MAPE\\ [0.8ex] 
\hline\hline
DSHW(7, 364) & 26197.65 & 88891.45 & 68771.39  & 1.66 & 4.33 \\
BATS(7, 365) & -46316.36  & 98041.36  & 77747.46  & -2.84  & 4.88\\
\hline
LR+ DSHW(7, 364) & 137934.59 & 165886.30 & 140175.06  & 8.42 & 8.55 \\
LR+ BATS(7, 365) & 40750.45 & 78797.68 & 54005.67 & 2.49 & 3.31 \\
\hline
\caption{Long-term Forecast Performance}
\label{tab:Dfor2}
\end{tabular}
\end{table}

However, it takes a long time to run PDFLaTeX, and shows:

Error: You can't use \hrule here except with leaders.

Warning: `Package caption Warning: \label without proper reference on input line 514.

3
  • 3
    \caption and \label should go outside the tabular.
    – egreg
    Aug 25, 2016 at 17:35
  • 2
    Move \caption and \label between \end{tabular} and \end{table}. Aug 25, 2016 at 17:36
  • Tabular with 6 columns, not 7. Aug 25, 2016 at 17:48

1 Answer 1

7

Suggestion with package booktabs for rules with better spacing and package siunitx for formatting the numbers and aligning them in the columns at the decimal marker. The first column is not changed, because I have not understood it (e.g., is the plus sign a suffix/part of LR or it is a "binary" operator?). The line between the data rows is replaced by some extra space to avoid the excessive use of rules.

Often table captions are above the tabular, because the tables are read top to down. Package caption fixes the caption spacing before and after for table captions above the tabular.

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

\begin{document}
  \begin{table}
    \centering
    \caption{Long-term Forecast Performance}
    \label{tab:Dfor2}
    \begin{tabular}{
      c
      S[table-format=-5.2]
      S[table-format=6.2]
      S[table-format=6.2]
      S[table-format=-1.2]
      S[table-format=1.2]
    }
      \toprule
      & {ME} & {RMSE} & {MAE} & {MPE} & {MAPE} \\
      \midrule
      DSHW(7, 364) & 26197.65 & 88891.45 & 68771.39  & 1.66 & 4.33 \\
      BATS(7, 365) & -46316.36  & 98041.36  & 77747.46  & -2.84  & 4.88 \\
      \addlinespace
      LR+ DSHW(7, 364) & 137934.59 & 165886.30 & 140175.06  & 8.42 & 8.55 \\
      LR+ BATS(7, 365) & 40750.45 & 78797.68 & 54005.67 & 2.49 & 3.31 \\
      \bottomrule
    \end{tabular}
  \end{table}
\end{document}

Result

2
  • 1
    Thanks a lot, it looks nice! I do not understand what does S[table-format=-5.2] mean. So I need to specify a value for each column separately?
    – Jeannie
    Aug 25, 2016 at 18:10
  • 4
    @Jeannie, S[table-format=-5.2] would be a column of type S, from siunitx, which makes typesetting numbers and units a lot more consistant. The optional argument specifies how many integers(5, with possible negative value), and decimals(2) to make room for. Have a look at the section tabular material in the manual for siunitx for more information.
    – Runar
    Aug 25, 2016 at 18:43

You must log in to answer this question.

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