儘管居中,列的大小並不相同

儘管居中,列的大小並不相同

我做了一張像這樣的桌子

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
  \begin{document}
    \begin{table}[htb]
        \centering
        \caption{Reproduzierbarkeit der Elektroden}
        \begin{tabular}{ccccc|c|c|c|c|}
            \toprule
                \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\  
            \midrule
                &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
            \cmidrule[0.5pt]{2-9}
                 6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
            \bottomrule
            \label{tab:reproduzierbarkeit}
        \end{tabular} 
    \end{table}
  \end{document}

我得到的是:

在此輸入影像描述

那麼,儘管所有行都居中,為什麼第九列的寬度比其他列大呢?我該如何更改它,以使每列具有相同的寬度?

謝謝!

答案1

您需要確保跨單元格比多列條目寬。

在此輸入影像描述

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
  \begin{document}
    \begin{table}[htb]
        \centering
        \newcommand\x{\makebox[1pt]{}}
        \caption{Reproduzierbarkeit der Elektroden}
        \begin{tabular}{@{}c*4{>\x c<\x}|*4{>\x c<\x|}@{}}
            \toprule
                \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\  
            \midrule
                &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
            \cmidrule[0.5pt]{2-9}
                 6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
                 9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
            \bottomrule
            \label{tab:reproduzierbarkeit}
        \end{tabular} 
    \end{table}
  \end{document}

答案2

你可以這樣做。我不知道你到底想要哪些寬度相等。這使得最後四列使用新的列類型具有相同的寬度H

\documentclass{article}
\usepackage{array,calc}
\newlength{\origtabcolsep}
\setlength{\origtabcolsep}{\tabcolsep}
\newlength{\mycolswidth}
\settowidth{\mycolswidth}{\textbf{maximale Abweichung [\%]}}
\newlength{\mycolwidth}
\setlength{\mycolwidth}{.25\mycolswidth-.75\tabcolsep}
\newcolumntype{H}{>{\centering\arraybackslash}p{\mycolwidth}|}
\usepackage{booktabs}
\begin{document}
  \begin{table}[htb]
      \centering
      \caption{Reproduzierbarkeit der Elektroden}
      \setlength{\tabcolsep}{.75\origtabcolsep}
      \begin{tabular}{*{5}{c}|*{4}{H}}
          \toprule
              \textbf{Elektrode} &\multicolumn{4}{c}{\textbf{Mittelwert [mV]}} &\multicolumn{4}{c}{\textbf{maximale Abweichung [\%]}} \\
          \midrule
              &pH 6 &pH 7 & pH 8 &pH 9 &pH 6 &pH 7 &pH 8&pH 9\\
          \cmidrule[0.5pt]{2-9}
               6 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               7 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               8 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
               9 & 111 & 111 & 111 & 111 & 10 & 12 & 13 & 11\\
          \bottomrule
          \label{tab:reproduzierbarkeit}
      \end{tabular}
  \end{table}
\end{document}

最後 4 列使用新列類型 H 的表格

相關內容