0

can someone help me with aligning my table using multicolumn and cmidrule. I have a long table with 19 columns and used \tiny to get the table on the page, but the lay out is not so nice. I want something like the second image.

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X

\begin{table}[htbp]
\tiny
  \centering
  \caption{ARMA order selection}
  \begin{tabular}{*{19}{l}}
    \toprule
    & \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI} 
      & \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(lr){6-7}
    \cmidrule(lr){8-9}
    \cmidrule(lr){10-11}
    \cmidrule(lr){12-13}
    \cmidrule(lr){14-15}
    \cmidrule(lr){16-17}
    \cmidrule(lr){18-19}
    & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC \\
    \midrule
    ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8  \\
    ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 &\\
    ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 &\\
    ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3  &\\
    ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 &\\
    ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 &\\
    \bottomrule
  \end{tabular}
  \label{Selection of ARMA orders}
\end{table}

enter image description here

enter image description here

7
  • 1
    Welcome to TeX.SX! Please prepar a complete and compilable minimal working example (MWE) that others can use to reproduce the output you get. If I try to build such a MWE based on the information your provided so far, I end up with a remarkably different output.
    – leandriis
    May 16, 2021 at 13:49
  • Also, you declare a total of 19 columns and seem to need exactly 19 columns, but some of your table rows contin an extra & right before the \\ which should cause an error message. Remove the extra &s.
    – leandriis
    May 16, 2021 at 13:51
  • What do you mean with the lay out is not so nice? You can try removing the & in `&\\` for better alignment ...
    – Excelsior
    May 16, 2021 at 13:51
  • I have added an image for the lay out I prefer
    – Abderrahim
    May 16, 2021 at 13:58
  • 1
    Please also add the documentclass you currently use to your MWE. Do you use the geometry package? If so, include the corresponding settings, as well.
    – leandriis
    May 16, 2021 at 14:00

2 Answers 2

0

Centering the AIC and BIC and using \arraystretch helps a lot.

\documentclass{article}
\usepackage[textwidth=30cm]{geometry}
\usepackage{booktabs}
\newcommand{\SH}{\multicolumn{1}{c}{AIC} & \multicolumn{1}{c}{BIC}} % subhead
\begin{document}
\begin{table}[htbp]
\tiny
  \centering
  \setlength{\abovetopsep}{10pt}
  \renewcommand{\arraystretch}{1.2}
  \caption{ARMA order selection}
  \begin{tabular}{*{19}{l}}
    \toprule
    & \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI} 
      & \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(lr){6-7}
    \cmidrule(lr){8-9}
    \cmidrule(lr){10-11}
    \cmidrule(lr){12-13}
    \cmidrule(lr){14-15}
    \cmidrule(lr){16-17}
    \cmidrule(lr){18-19}
    & \SH & \SH & \SH & \SH & \SH & \SH & \SH & \SH & \SH \\
    \midrule
    ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8  \\
    ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
    ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
    ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
    \bottomrule
  \end{tabular}
  \label{Selection of ARMA orders}
\end{table}

\end{document}

enter image description here

1
  • You might want to explicitly mention that you drastically increased the paper size in order to get the table to fit.
    – leandriis
    May 16, 2021 at 14:17
0

To make your code compilable, replace & \\ with \\ . Otherwise, you end up with the error message Extra alignment tab has been changed to \cr.. Once you get an error message, don't look at the resulting pdf file, but ix the error first.

Now that the code compiles properly, we can take a look at the output and see that the table is, even with a \tiny font size, still far too wide to fit onto the page. I therefore suggest splitting it up. I additionally changed the horizontal alignment from left aligned to centered.

enter image description here

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{booktabs}
\usepackage{caption}
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{ARMA order selection}
  \begin{tabular}{l *{6}{c}}
    \toprule
      & \multicolumn{2}{c}{DJI}  & \multicolumn{2}{c}{NIKKEI} & \multicolumn{2}{c}{TSX} 
 \\
    \cmidrule(r){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(l){6-7}
    & AIC & BIC & AIC & BIC & AIC & BIC  \\
    \midrule
    ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 \\
    ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 \\
    ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 \\
    ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 \\
    ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 \\
    ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 \\
    \midrule
     & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC}  \\
    \cmidrule(r){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(l){6-7}
    & AIC & BIC & AIC & BIC & AIC & BIC  \\
    \midrule
    ARMA(1,0)  & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2  \\
    ARMA(0,1)  & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3  \\
    ARMA(1,1)  & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3  \\
    ARMA(2,1)  & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1  \\
    ARMA(1,2)  & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8  \\
    ARMA(2,2)  & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8  \\
    \midrule
     & \multicolumn{2}{c}{SSE}  & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
    \cmidrule(r){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(l){6-7}
    & AIC & BIC & AIC & BIC & AIC & BIC \\
    \midrule
    ARMA(1,0) & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
    ARMA(0,1) & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
    ARMA(1,1) & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
    ARMA(2,1) & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    ARMA(1,2) & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    ARMA(2,2) & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
    \bottomrule
  \end{tabular}
  \label{Selection of ARMA orders}
\end{table}


\begin{table}[htbp]
  \centering
%  \small
  \caption{ARMA order selection}
  \begin{tabular}{l*{10}{c}}
    \toprule
    & \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI} 
      & \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} \\
    \cmidrule(r){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(lr){6-7}
    \cmidrule(lr){8-9}
    \cmidrule(l){10-11}
    ARMA & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC  \\
    \midrule
    (1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 \\
    (0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 \\
    (1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 \\
    (2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 \\
    (1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 \\
    (2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 \\
    \midrule
    &  \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
    \cmidrule(r){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(lr){6-7}
    \cmidrule(l){8-9}
    ARMA & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC \\
    \midrule
    (1,0) & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
    (0,1) & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
    (1,1) & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
    (2,1) & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    (1,2) & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
    (2,2) & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
    \bottomrule
  \end{tabular}
  \label{Selection of ARMA orders}
\end{table}

\end{document}
5
  • This looks great, however when i use this code i still get no space between the columns. Is that because i have used tabularx somewhere else?
    – Abderrahim
    May 16, 2021 at 14:23
  • Did you try to compile my code as it is or did you include the table into your actual document? The use of tabularx isn't related to the issue, but I guess, you somewhere reduced the value of \tabcolsep using \setlength{\tabcolsep}{1pt} or something similar. Is that the case?
    – leandriis
    May 16, 2021 at 14:27
  • yes I used the \setlength{\tabcolsep}{1pt}, however when i change it to tabularx i almost got the table you presented however the cmidrule isn't aligned like yours.
    – Abderrahim
    May 16, 2021 at 14:30
  • Don't use tabularx for the table at hand, especially not, if there is no X type column involved. Instead, either remove the \setlength{\tabcolsep}{1pt} or, if you need it for some resaon for a different table, make sure it is limited to this particular table only.
    – leandriis
    May 16, 2021 at 14:32
  • It worked thank you very much!
    – Abderrahim
    May 16, 2021 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.