你能修复一下这个表吗?列是正确的。我有 5 列,如以下代码第一行所示。
\newcolumntype{C}{>{\centering\arraybackslash}X}
`\lipsum[1]
\begin{table}[!h]
\caption{Running times in seconds on symmetric MINLP.}
\label{Table}
\begin{tabularx}{\textwidth}{@{} c>{\hsize=0.5\hsize}C
>{\hsize=1.5\hsize}C
@{} }
\toprule
Name & Algorithm & Cycle & Total time (s) & Number of sub-problems \\
\midrule
P1 & 1 & $ (1,2,3,4,5)$ & .. & .. \\
\midrule
P2 & 2 & $ (1,15,7,5,12) $ & .. & .. \\
\midrule
P2 & 3 & $(1,15,7,5,12),(2,9,13,14,8) $ & ... &...\\
\midrule
P3 & 2 & $(1,7,12,16,19,21,6)$ & ... & ...\\
\midrule
P3 & 3 & $(1,7,12,16,19,21,6), (2 ,8 ,13, 17, 20, 5, 11)$ & ... & ...\\
\midrule
P4 & 2 & $(( 1, 3, 5, 6, 7,22,13,23)$ & ... & ...\\
\midrule
P4 & 2 & $( 1, 3, 5, 6, 7,22,13,23), (4,15,16,17,14,21,19,12)$ & ... & ...\\
\bottomrule
\end{tabularx}
\end{table}
\lipsum[2]`
答案1
你声明了三列,但使用了五列,运行 LaTeX 肯定会显示许多错误信息:永远不要忽视它们
标题占据了大部分空间,只留下了一小部分给“周期”栏。我的建议是缩短标题,在底部添加说明。
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[!htp]
\caption{Running times in seconds on symmetric MINLP.}\label{Table}
\begin{tabularx}{\textwidth}{@{}ccCcc@{}}
\toprule
%Name & Algorithm & Cycle & Total time (s) & Number of sub-problems \\
N & A & C & TT (s) & NS \\
\midrule
P1 & 1 & $(1,2,3,4,5)$ & .. & .. \\
%\midrule
P2 & 2 & $(1,15,7,5,12)$ & .. & .. \\
%\midrule
P2 & 3 & $(1,15,7,5,12)$, $(2,9,13,14,8)$ & ... &...\\
%\midrule
P3 & 2 & $(1,7,12,16,19,21,6)$ & ... & ...\\
%\midrule
P3 & 3 & $(1,7,12,16,19,21,6)$, $(2,8,13,17,20,5,11)$ & ... & ...\\
%\midrule
P4 & 2 & $(1,3,5,6,7,22,13,23)$ & ... & ...\\
%\midrule
P4 & 2 & $(1,3,5,6,7,22,13,23)$, $(4,15,16,17,14,21,19,12)$ & ... & ...\\
\midrule[\heavyrulewidth]
\multicolumn{5}{@{}l@{}}{N: Name; A: Algorithm; C: Cycle; TT: Total time;}\\
\multicolumn{5}{@{}l@{}}{NS: Number of subproblems}\\
\end{tabularx}
\end{table}
\end{document}
请注意,每个循环都用其自己的符号输入$...$
,因此当有两个以上的循环时,可能会出现换行符。
我会避免在每行之间添加规则。
答案2
这应该满足要求——正如@quark67 指出的那样,列数为 5,而分隔符&
只有 3——更重要的是,OP 忘记在$
括号外面用数学符号括起来,而第三列中必须强制使用新行
平均能量损失
\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{makecell, multirow, tabularx}
\usepackage{booktabs, ragged2e}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{%
@{}
c
C
C
c
c
@{}} \toprule
Name & Algorithm & Cycle & Total time (s) & Number of \\
&&&&sub-problems\\\midrule
P1 & 1 & $(1,2,3,4,5)$ & .. & .. \\ \midrule
P2 & 2 & $(1,15,7,5,12)$ & .. & .. \\ \midrule
P2 & 3 & $(1,15,7,5,12)$, $(2,9,13,14,8)$ & ... &...\\ \midrule
P3 & 2 & $(1,7,12,16,19,21,6)$ & ... & ...\\ \midrule
P3 & 3 & $(1,7,12,16,19,21,6)$, $(2 ,8 ,13, 17, 20, 5, 11)$ & ... & ...\\
\midrule
P4 & 2 & $( 1, 3, 5, 6, 7,22,13,23)$ & ... & ...\\ \midrule
P4 & 2 & $( 1, 3, 5, 6, 7,22,13,23)$, $(4,15,16,17,14,21,19,12)$ & ... & ...\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}