3

I need to add one more column to the table and add $L$ parameter next to $n$. How can I add it?

mwe:

\documentclass{article}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{setspace}
\begin{document}


\begin{table}[htbp]
    \small
    \begin{spacing}{1}
        \begin{center}
            \begin{tabular}{|*{8}{c|}}  % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
                \hline
                &   &   & \multicolumn{2}{c|}{\textbf{ML }}
                & \multicolumn{2}{c|}{\textbf{ML  }}  \\
                \cline{3-7}
                $\lambda$   & $\gamma$  & $n$& & Train    &  Test      & Train  & Test \\
                \hline
                0.01        & 0.006     & 30  &  & 0.9133    &    \textbf{0.9401}    &       &   \\
                \hline
                0.01        & 0.002     & 50   & &           & &0.8973       &  \textbf{0.9080} \\
                \hline
            \end{tabular}
            \caption{Values.}
            \label{mejorrmsepredictorbase}
        \end{center}
    \end{spacing}
\end{table}

\end{document}

I am getting something like this, which is awful:

enter image description here

I would like to leave it like $\lambda$ and \gamma, meaning, alone.

NaveganTeX
  • 2,630
  • 2
    Ehm, you just write it into the table ... & starts a new column, so you add another & at the appropriate place in each row, and new content before it. You've already specified 8 columns for the tabular, so you don't have to modify that – Torbjørn T. Jul 23 '19 at 21:18
  • I will try that. Yes, I added the 8. But then I also added & on one row only and it did the opposite – NaveganTeX Jul 23 '19 at 21:19
  • 1
    Each row, including the first row. – Torbjørn T. Jul 23 '19 at 21:24

1 Answers1

5

Basically you just need to add an additional & and new content in the appropriate position on each row, including the first row. And you need to change the column numbers for the \crule. I'm guessing you want \crule{5-8}?

I would consider setting the table without vertical rules, it looks better I think. And it's usually recommended using \centering instead of the center environment, see Should I use center or centering for figures and tables?

enter image description here

\documentclass{article}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{booktabs} % provides \toprule, \bottomrule,\midrule, \cmidrule
\begin{document}


\begin{table}[htbp]
    \small
    \centering
            \begin{tabular}{|*{8}{c|}}  % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between
                \hline
                &  &  &   & \multicolumn{2}{c|}{\textbf{ML }}
                & \multicolumn{2}{c|}{\textbf{ML  }}  \\
                \cline{5-8}
                $\lambda$   & $\gamma$  & $n$& $L$ &  Train    &  Test      & Train  & Test \\
                \hline
                0.01        & 0.006  & 30 & 1       & 0.9133    &    \textbf{0.9401}    &       &   \\
                \hline
                0.01        & 0.002  & 50 & 2      &           & &0.8973       &  \textbf{0.9080} \\
                \hline
            \end{tabular}
            \caption{Values.}
            \label{mejorrmsepredictorbase}
\end{table}

\begin{table}[htbp]
    \small
    \centering
            \begin{tabular}{*{8}{c}}
                \toprule
                &  &  &   & \multicolumn{2}{c}{\textbf{ML}}
                & \multicolumn{2}{c}{\textbf{ML}}  \\
                \cmidrule(lr){5-6} \cmidrule(lr){7-8}
                $\lambda$   & $\gamma$  & $n$& $L$ &  Train    &  Test      & Train  & Test \\
                \midrule
                0.01        & 0.006  & 30 & 1       & 0.9133    &    \textbf{0.9401}    &       &   \\
                0.01        & 0.002  & 50 & 2      &           & &0.8973       &  \textbf{0.9080} \\
                \bottomrule
            \end{tabular}
            \caption{Values.}
            \label{mejorrmsepredictorbase}
\end{table}

\end{document}
Torbjørn T.
  • 206,688