[Tex/LaTex] Multicolumn and thead problem in tabularx

lyxtablestabularx

I am trying to implement a code using tabularx and multicolumn along with head, but I keep on getting an error. The code is as follows:

\begindocumnet{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{ragged2e}
\newcolumntype{L}{ >{\RaggedRight}X }
\usepackage{siunitx}
\usepackage{makecell}
\renewcommand\theadfont{\normalfont\bfseries}
\setlength\parindent{0pt}
\newcolumntype{Y}{ >{\Centering}X}
\usepackage[justification=centering]{caption}

\noindent 

\newcolumntype{Y}{ >{\Centering}X} 
\begin{tabularx}{\textwidth}{@{} lYYY @{}}  

\toprule 


\thead[lc]{Category}   & \multicolumn{2}{c}{\thead{Forecasting Horizon}}& 

& \multicolumn{2}{c}{\thead{1 Period}} & {\multicolumn{2}{c}{1 Period}} & 

\multicolumn{2}{c}{\thead{3 Period}}  \\


&  \thead{TSMOM (1,1)} & \thead{TSMOM (3,3)} 

& \thead{TSMOM (1,1)} & \thead{TSMOM (3,3)} & \thead{TSMOM (1,1)} 

& \thead{TSMOM (3,3)} \\

\midrule  

Test-Statistic & 0 & 1.00 & 1.00 \\ \addlinespace

P-value & 0 & 0.59 & 1.00 \\ \addlinespace  

\bottomrule  

\end{tabularx}

To provide an idea, I basically want to make a chart with the following content

enter image description here

except I would like to have the layout in the following format :

enter image description here

However, I get the following error such as: "extra alignment tab has been change to \cr" could someone please help advise me where I am making a mistake with the code ? Thank you

Best Answer

You have mismatch in MWE (one multicolum is probably accidentally repeated). Corrected (and slightly improved) code is:

\documentclass{article}
    \usepackage{booktabs,makecell,multirow,tabularx}
\renewcommand\theadfont{\normalfont\bfseries}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcolumntype{C}{>{\Centering\arraybackslash}X}

\newcommand\mc[1]{\multicolumn{2}{c}{#1}}
    \usepackage[justification=centering]{caption}
    \usepackage{ragged2e}
    \usepackage{siunitx}

    \usepackage[margin=20mm]{geometry}
\setlength\parindent{0pt}

    \begin{document}
\begin{tabularx}{\textwidth}{@{} l *{6}{C} @{}}
    \toprule
\thead{Forecasting Horizon}
    &   \mc{\thead{1 Period}}
        &   \mc{\thead{2 Period}}
            &   \mc{\thead{3 Period}}               \\
    \cmidrule(rl){2-3}\cmidrule(rl){4-5}\cmidrule(rl){6-7}
\thead{strategies}
    &  \thead{TSMOM\\ (1,1)}
        &   \thead{TSMOM\\ (3,3)}
            &   \thead{TSMOM\\ (1,1)}
                &   \thead{TSMOM\\ (3,3)}
                    &   \thead{TSMOM\\ (1,1)}
                        &   \thead{TSMOM\\ (3,3)}   \\
    \midrule
Test-Statistic
    & \mc{0} & \mc{1.00} & \mc{1.00}                \\ 
    %\addlinespace
P-value & \mc{0} & \mc{0.59} & \mc{1.00}            \\
    \bottomrule
\end{tabularx}
    \end{document}

enter image description here