表格中的列宽不一致

表格中的列宽不一致
\begin{table}[h!]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|l|}
    \hline
    \multicolumn{3}{|l|}{} & \multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}Filament Voltage: 6.0 V\\ Collector Voltage: 2.0 V\\ Oven Temperature: $160^{\circ}$C\end{tabular}} & \multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}Filament Voltage: 6.0 V\\ Collector Voltage: 2.0 V\\ Oven Temperature: $160^{\circ}$C\end{tabular}} \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at first \\ minima/maxima {[}V{]}\end{tabular}} & 0 & 2.2 & 0 & 2.2 \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at second \\ minima/maxima {[}V{]}\end{tabular}} & 4.6 & 5.2 & 4.3 & 7.2 \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at third \\ minima/maxima {[}V{]}\end{tabular}} & 9.6 & 12.4 & - & - \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage difference \\ between the first and \\ the second \\ minima/maxima {[}V{]}\end{tabular}} & 4.6 & 3.0 & 4.3 & 5.0 \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage difference \\ between the second and \\ the third \\ minima/maxima {[}V{]}\end{tabular}} & 5.0 & 7.2 & - & - \\ \hline
    \multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Mean of Voltage \\ difference between \\ the minima/maxima {[}V{]}\end{tabular}} & 4.8 & 5.1 & 4.3 & 5.0 \\ \hline
\end{tabular}
**strong text**\end{table}

我对较宽的列有疑问,我不知道为什么它们不一样?有人能帮我吗?谢谢

答案1

由于存在一次跨越两列的标题单元格,因此需要明确计算包含数字数据的四列的宽度。以下代码显示了如何实现这一点。

我还建议您简化表格中的代码,让第一列中的文本自动换行,并让第一列的宽度确定为文本块的宽度与第 2 列至第 5 列的总宽度之间的差值。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,ragged2e}
% Calculate width of columns 2 to 5
\newlength\mylength
\settowidth{\mylength}{Oven Temperature: $160^{\circ}$C}
\addtolength\mylength{-2\tabcolsep}
\addtolength\mylength{-\arrayrulewidth}
\setlength\mylength{\dimexpr\mylength/2\relax}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
% Width of column 1 is a residual
\newcolumntype{Y}{>{\RaggedRight}X}
% Handy shortcut macro
\newcommand\mc[1]{\multicolumn{2}{c|}{#1}}

\begin{document}
\begin{table}[h!]
\setlength\tabcolsep{4pt}
\caption{My caption} \label{my-label}
\begin{tabularx}{\textwidth}{|Y|*{4}{P{\mylength}|}}
\hline
& \mc{Filament Voltage: 6.0 V} & \mc{Filament Voltage: 6.0 V} \\
& \mc{Collector Voltage: 2.0 V} & \mc{Collector Voltage: 2.0 V} \\
& \mc{Oven Temperature: $160^{\circ}$C} & \mc{Oven Temperature: $160^{\circ}$C} \\
\hline
Voltage at first minimum\slash maximum [V] & 0 & 2.2 & 0 & 2.2 \\ \hline
Voltage at second minimum\slash maximum [V] & 4.6 & 5.2 & 4.3 & 7.2 \\ 
\hline
Voltage at third minimum\slash maximum [V] & 9.6 & 12.4 & - & - \\ \hline
Voltage difference between first and second minima\slash maxima [V] & 4.6 & 3.0 & 4.3 & 5.0 \\ 
\hline
Voltage difference between second and third minima\slash maxima [V] & 5.0 & 7.2 & - & - \\ 
\hline
Mean of Voltage difference between the minima\slash maxima [V] & 4.8 & 5.1 & 4.3 & 5.0 \\ 
\hline
\end{tabularx}
\end{table}
\end{document}

相关内容