我得到了一个在类型列内有多列的表X
。在《The LaTeX Companion》中,明确指出“任何\multicolumn
跨越任何 X 列的条目都不应使用。”违反该规则会导致如下异常
如果我仍然想获得类型列的好处X
(自动匹配列宽,甚至根据另一列的宽度指定一列的宽度),但我想使用,\multicolumn
该怎么办?有没有办法同时获得两者?
我想要的输出是这样的
但是,当然,没有超出表格宽度的线。
\documentclass{article}
\usepackage{multirow}
\usepackage{caption}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{ >{ \arraybackslash \Centering } X }
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{mathastext}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\begin{table}[htb]
% Table options
% Caption
\caption{Comparison of Time Consumed to Estimate One $\mathnormalbold{Z}_{bus}$ Element}
\label{table:time_cons_comp}
% Center the table
\centering
\begin{tabularx}{0.7\textwidth}{C |C |C |C}
\toprule
\multirow{3}{=}{\centering System Size} & \multicolumn{3}{c}{Time Needed With Our Approach (Extended Brown's Method)}
\\
\Xcline{2-4}{0.1mm}
& min & mean & max
\\
\Xhline{0.1mm}
200-bus & $6\times10^{-6}$ & $7.7\times10^{-6}$ & $9\times10^{-6}$
\\
\Xhline{0.1mm}
2383-bus & $6\times10^{-6}$ & $9.1\times10^{-6}$ & $13\times10^{-6}$
\\
\Xhline{0.1mm}
3120-bus & $8\times10^{-6}$ & $9.7\times10^{-6}$ & $11\times10^{-6}$
\\
\hline
\hline
\multirow{3}{=}{\centering System Size} & \multicolumn{3}{c}{Time Needed With Conventional Brown's Method}
\\
\Xcline{2-4}{0.1mm}
& min & mean & max
\\
\Xhline{0.1mm}
200-bus & $0.089$ & $0.092$ & $0.1000$
\\
\Xhline{0.1mm}
2383-bus & $163.8$ & $166.2$ & $172.5$
\\
\Xhline{0.1mm}
3120-bus & $387.2$ & $398.8$ & $415.6$
\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
- 在新列的定义中,您应该删除所有空格
- 多列中的文本
cell
比跨度单元格的宽度更宽 - 命令
\mathnormalbold
未知(至少对我来说)
和
\documentclass{article}
\usepackage{caption}
\usepackage{ragged2e}
%\usepackage{booktabs} % not used in this table
\usepackage{makecell}
\usepackage{multirow}
\usepackage{tabularx}
\newcolumntype{C}{>{\Centering}X }
\usepackage{mathastext}
\begin{document}
\begin{table}[htb]
\renewcommand{\arraystretch}{1.2}
\caption{Comparison of Time Consumed to Estimate One $\mathbf{Z}_{bus}$ Element}
\label{table:time_cons_comp}
\centering
\begin{tabularx}{0.8\textwidth}{C *{3}{|>{$}C<{$} } }
\Xhline{0.3mm}
\multirow{3}{=}{\centering System Size}
& \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed With Our Approach \newline
(Extended Brown's Method)} \\
\Xcline{2-4}{0.1mm}
& min & mean & max \\
\Xhline{0.1mm}
200-bus & 6\times10^{-6} & 7.7\times10^{-6} & 9\times10^{-6} \\
\Xhline{0.1mm}
2383-bus & 6\times10^{-6} & 9.1\times10^{-6} & 13\times10^{-6} \\
\Xhline{0.1mm}
3120-bus & 8\times10^{-6} & 9.7\times10^{-6} & 11\times10^{-6} \\
\hline
\hline
\multirow{3}{=}{\centering System Size}
& \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed With\newline
Conventional Brown's Method} \\
\Xcline{2-4}{0.1mm}
& min & mean & max \\
\Xhline{0.1mm}
200-bus & 0.089 & 0.092 & 0.100 \\
\Xhline{0.1mm}
2383-bus & 163.8 & 166.2 & 172.5 \\
\Xhline{0.1mm}
3120-bus & 387.2 & 398.8 & 415.6 \\
\Xhline{0.3mm}
\end{tabularx}
\end{table}
\end{document}
你将获得以下结果:
编辑:
我认为大卫·卡莱尔关于单元格宽度的评论multicolumn
。还考虑技术员删除所有不必要的水平和垂直线
\documentclass{article}
\usepackage{caption}
\usepackage{ragged2e}
%\usepackage{booktabs} not used
\usepackage{makecell}
\usepackage{multirow}
\usepackage{tabularx}
\newcolumntype{C}{ >{\Centering}X }
\usepackage{mathastext}
\begin{document}
\begin{table}[htb]
\renewcommand{\arraystretch}{1.2}
\caption{Comparison of Time Consumed to Estimate One $\mathbf{Z}_{bus}$ Element}
\label{table:time_cons_comp}
\centering
\begin{tabularx}{0.8\textwidth}{C *{3}{>{$}C<{$} }}
\Xhline{0.3mm}
\multirow{3}{=}{\centering System Size}
& \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed With Our Approach \newline
(Extended Brown's Method)} \\
\cline{2-4}
& min & mean & max \\
\hline
200-bus & 6\times10^{-6} & 7.7\times10^{-6} & 9\times10^{-6} \\
2383-bus & 6\times10^{-6} & 9.1\times10^{-6} & 13\times10^{-6} \\
3120-bus & 8\times10^{-6} & 9.7\times10^{-6} & 11\times10^{-6} \\
\hline
\hline
\multirow{3}{=}{\centering System Size}
& \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed With\newline
Conventional Brown's Method} \\
\cline{2-4} & min & mean & max \\
\Xhline{0.1mm}
200-bus & 0.089 & 0.092 & 0.100 \\
2383-bus & 163.8 & 166.2 & 172.5 \\
3120-bus & 387.2 & 398.8 & 415.6 \\
\Xhline{0.3mm}
\end{table}
\end{document}
答案2
这是另一种解决方案。三列标题单元格的宽度计算为3\hsize+ 4\tabcolsep
,其中\hsize
是三个数据列中每个列的可用宽度。(的值\hsize
由自动计算tabularx
。)选择3\hsize+4\tabcolsep
考虑到三个数据列的组合比三个单独列的简单总和更宽:还有两个列间空白实例,每个实例的数量为2\tabcolsep
,需要考虑。
下面的代码还加载了该siunitx
包并使用该包的\num
宏,以简化科学格式的数字输入。另外,我建议省略所有垂直线:它们根本就没有必要。事实上,有人可能会认为省略垂直线改善表格的整体可读性显著提高。
\documentclass{article}
%% (I've simplified the preamble to the minimum that's required.)
\usepackage{caption,booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{siunitx} % new -- for "\num" macro
\renewcommand{\arraystretch}{1.2}
\begin{document}
\begin{table}[htb]
\caption{Comparison of Times Consumed to Estimate One $Z_{\mathrm{bus}}$ Element}
\label{table:time_cons_comp}
\centering
\begin{tabularx}{0.7\textwidth}{@{}lCCC@{}}
\toprule
System Size &
\multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed with Our Approach (Extended Brown's Method)}\\
\cmidrule(l){2-4}
& min & mean & max\\
\midrule
200-bus & \num{6e-6} & \num{7.7e-6} & \num{9e-6} \\
2383-bus & \num{6e-6} & \num{9.1e-6} & \num{3e-6} \\
3120-bus & \num{8e-6} & \num{9.7e-6} & \num{11e-6} \\
\midrule[\heavyrulewidth]
System Size &
\multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep\relax}C}{%
Time Needed with Conventional~Brown's Method}\\
\cmidrule(l){2-4}
& min & mean & max\\
\midrule
200-bus & $0.089$ & $0.092$ & $0.100$ \\
2383-bus & $163.8$ & $166.2$ & $172.5$ \\
3120-bus & $387.2$ & $398.8$ & $415.6$ \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}