如何让表格适合边距?

如何让表格适合边距?

我怎样才能让这个表格适合左边距和右边距?

\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}

有人能帮帮我吗?使用\makebox不是一个好的输出!

编辑:

\textwidth 15cm

答案1

将重复的信息从exp-resLayer每个头部移出并放在它们上方,\multicolumn会对表格宽度产生神奇的效果:

\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}

在此处输入图片描述

编辑:如果应该更清楚地表明每一列应该是这样的,exp-resLayer<i>那么可以将其更改为:

\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}

在此处输入图片描述

我认为这是一个更漂亮的版本,没有那些垂直规则,而且水平规则也更少:

\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}

在此处输入图片描述

答案2

如果允许分numItersForTrainExamplesHistory两行,你可以把第一列弄窄一点,用大一点的字体,但这样就\footnotesize行了

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


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


    \begin{document}


        \begin{table}
        \centering
        \setlength\tabcolsep{4pt}
        \footnotesize
        \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}

答案3

虽然我个人肯定更喜欢Skillmon 的方法,这里是使用旋转列标题的变体:

在此处输入图片描述

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

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

\usepackage{makecell,rotating}

\begin{document}
\begin{table}
\settowidth\rotheadsize{\theadfont exp-resLayer10-lr}
\renewcommand\cellrotangle{55}
\centering
  \begin{tabular}{|l|c|c|c|c|c|}
    \hline
      & base & \rothead{exp-resLayer2} & \rothead{exp-resLayer10} & \rothead{exp-resLayer2-lr} & \rothead{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}

相关内容