![儘管居中,列的大小並不相同](https://rvso.com/image/286344/%E5%84%98%E7%AE%A1%E5%B1%85%E4%B8%AD%EF%BC%8C%E5%88%97%E7%9A%84%E5%A4%A7%E5%B0%8F%E4%B8%A6%E4%B8%8D%E7%9B%B8%E5%90%8C.png)
我做了一張像這樣的桌子
\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}