[Tex/LaTex] How make a table fit inside the margins

horizontal alignmentmarginstables

How can I make this table fit inside left and right margin?

\documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage{array}


          \textwidth 15cm
          \textheight 22cm
          \parindent 10pt
          \oddsidemargin 0.85cm
          \evensidemargin 0.37cm


    \begin{document}
        \begin{table}
        \noindent
        \begin{tabular}{|c|c|c|c|c|c|}
        \hline
                                                                & base                         & \multicolumn{1}{l|}{exp-resLayer2} & \multicolumn{1}{l|}{exp-resLayer10} & \multicolumn{1}{l|}{exp-resLayer2-lr} & \multicolumn{1}{l|}{exp-resLayer10-lr} \\ \hline
         numIters                        &  20   & 20                                 & 20                                  & 20                                    & 20                                     \\ \hline
         numEps                          &  20   & 20                                 & 20                                  & 20                                    & 20                                     \\ \hline
         tempThreshold                   &  400  & 400                                & 400                                 & 400                                   & 400                                    \\ \hline
         updateThreshold                 &  0.54 & 0.54                               & 0.54                                & 0.54                                  & 0.54                                   \\ \hline
         numMCTSSims                     &  50   & 50                                 & 50                                  & 50                                    & 50                                     \\ \hline
         arenaCompare                    &  20   & 20                                 & 20                                  & 20                                    & 20                                     \\ \hline
         cpuct                           &  1    & 1                                  & 1                                   & 1                                     & 1                                      \\ \hline
         numItersForTrainExamplesHistory &  20   & 20                                 & 20                                  & 20                                    & 20                                     \\ \hline
                                         &       &                                    &                                     &                                       &                                        \\ \hline
         lr                              &  0.01 & 0.01                               & 0.001       & 0.01                                  & 0.001          \\ \hline
         epochs                          &  10   & 10                                 & 10                                  & 10                                    & 10                                     \\ \hline
         batch\_size                     &  32   & 32                                 & 32                                  & 32                                    & 32                                     \\ \hline
         residual\_block\_num            &  5    & 2                                  & 10                                  & 2                                     & 10                                     \\ \hline
         image\_stack\_layers            &  9    & 9                                  & 9                                   & 9                                     & 9                                      \\ \hline
        \end{tabular}
        \end{table}
\end{document}

May someone help me please? Using \makebox is not a good output!

EDIT:

\textwidth 15cm

Best Answer

Moving the duplicate information of exp-resLayer out of each head and above them in a \multicolumn does wonders to your table width:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{array}

\textwidth 15cm
\textheight 22cm
\parindent 10pt
\oddsidemargin 0.85cm
\evensidemargin 0.37cm

\begin{document}
\begin{table}
  \begin{tabular}{|l|c|c|c|c|c|}
    \hline
      & & \multicolumn{4}{c|}{exp-resLayer} \\
    \cline{3-6}
      & base & 2 & 10 & 2-lr & 10-lr \\
    \hline
    numIters & 20 & 20 & 20 & 20 & 20 \\
    \hline
    numEps & 20 & 20 & 20 & 20 & 20 \\
    \hline
    tempThreshold & 400 & 400 & 400 & 400 & 400 \\
    \hline
    updateThreshold & 0.54 & 0.54 & 0.54 & 0.54 & 0.54 \\
    \hline
    numMCTSSims & 50 & 50 & 50 & 50 & 50 \\
    \hline
    arenaCompare & 20 & 20 & 20 & 20 & 20 \\
    \hline
    cpuct & 1 & 1 & 1 & 1 & 1 \\
    \hline
    numItersForTrainExamplesHistory & 20 & 20 & 20 & 20 & 20 \\
    \hline
      & & & & & \\
    \hline
    lr & 0.01 & 0.01 & 0.001 & 0.01 & 0.001 \\
    \hline
    epochs & 10 & 10 & 10 & 10 & 10 \\
    \hline
    batch\_size & 32 & 32 & 32 & 32 & 32 \\
    \hline
    residual\_block\_num & 5 & 2 & 10 & 2 & 10 \\
    \hline
    image\_stack\_layers & 9 & 9 & 9 & 9 & 9 \\
    \hline
  \end{tabular}
\end{table}
\end{document}

enter image description here

EDIT: if it should be more clear that each of the columns should be something like exp-resLayer<i> then one could change that to:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{array}

\textwidth 15cm
\textheight 22cm
\parindent 10pt
\oddsidemargin 0.85cm
\evensidemargin 0.37cm

\begin{document}
\begin{table}
  \begin{tabular}{|l|c|c|c|c|c|}
    \hline
      & & \multicolumn{4}{c|}{exp-resLayer$\langle i\rangle$} \\
    \cline{3-6}
      & base & 2 & 10 & 2-lr & 10-lr \\
    \hline
    numIters & 20 & 20 & 20 & 20 & 20 \\
    \hline
    numEps & 20 & 20 & 20 & 20 & 20 \\
    \hline
    tempThreshold & 400 & 400 & 400 & 400 & 400 \\
    \hline
    updateThreshold & 0.54 & 0.54 & 0.54 & 0.54 & 0.54 \\
    \hline
    numMCTSSims & 50 & 50 & 50 & 50 & 50 \\
    \hline
    arenaCompare & 20 & 20 & 20 & 20 & 20 \\
    \hline
    cpuct & 1 & 1 & 1 & 1 & 1 \\
    \hline
    numItersForTrainExamplesHistory & 20 & 20 & 20 & 20 & 20 \\
    \hline
      & & & & & \\
    \hline
    lr & 0.01 & 0.01 & 0.001 & 0.01 & 0.001 \\
    \hline
    epochs & 10 & 10 & 10 & 10 & 10 \\
    \hline
    batch\_size & 32 & 32 & 32 & 32 & 32 \\
    \hline
    residual\_block\_num & 5 & 2 & 10 & 2 & 10 \\
    \hline
    image\_stack\_layers & 9 & 9 & 9 & 9 & 9 \\
    \hline
  \end{tabular}
\end{table}
\end{document}

enter image description here

An imho prettier version without all those vertical rules and less horizontal ones:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{array}

\textwidth 15cm
\textheight 22cm
\parindent 10pt
\oddsidemargin 0.85cm
\evensidemargin 0.37cm

\usepackage{booktabs}

\begin{document}
\begin{table}
  \begin{tabular}{l*5c}
    \toprule
      & & \multicolumn{4}{c}{exp-resLayer} \\
    \cmidrule{3-6}
      & base & 2 & 10 & 2-lr & 10-lr \\
    \midrule
    numIters & 20 & 20 & 20 & 20 & 20 \\
    numEps & 20 & 20 & 20 & 20 & 20 \\
    tempThreshold & 400 & 400 & 400 & 400 & 400 \\
    updateThreshold & 0.54 & 0.54 & 0.54 & 0.54 & 0.54 \\
    numMCTSSims & 50 & 50 & 50 & 50 & 50 \\
    arenaCompare & 20 & 20 & 20 & 20 & 20 \\
    cpuct & 1 & 1 & 1 & 1 & 1 \\
    numItersForTrainExamplesHistory & 20 & 20 & 20 & 20 & 20 \\
    \noalign{\medskip}
    lr & 0.01 & 0.01 & 0.001 & 0.01 & 0.001 \\
    epochs & 10 & 10 & 10 & 10 & 10 \\
    batch\_size & 32 & 32 & 32 & 32 & 32 \\
    residual\_block\_num & 5 & 2 & 10 & 2 & 10 \\
    image\_stack\_layers & 9 & 9 & 9 & 9 & 9 \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

enter image description here

Related Question