使用以下代码:
\begin{table}[H]
\centering
\caption{Caption }
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|p{2cm}||c|c|c|}
\hline
{\textbf{Molecule}} & {\textbf{Ground State Energy (Hartree)}} \\
\cline{2-4}
& \textbf{Multiplicity 1 } & \textbf{Multiplicity 3} & \textbf{Multiplicity 5}\\
\hline
$ \mathrm{C_4H_8N_2}$ & -264.84232294 & -264.8423229345 & -264.8423248314 \\
\end{tabular}
\label{tab:multiplicity}
\end{table}
我希望基态能量 Hartree 标题居中,以便它包含多重性 1、多重性 3 和多重性 5。换句话说,在第一行中,我如何删除创建第二列和第三列的线,然后将基态能量标题居中。
答案1
也许您只需要使用\multicolumn
如下命令:
\documentclass{article}
\usepackage{float}
\begin{document}
\begin{table}[H]
\centering
\caption{Some caption}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|p{2cm}||c|c|c|}
\hline
{\textbf{Molecule}} & \multicolumn{3}{c|}{\textbf{Ground State Energy (Hartree)}} \\
\cline{2-4}
& \textbf{Multiplicity 1 } & \textbf{Multiplicity 3} & \textbf{Multiplicity 5}\\
\hline
$ \mathrm{C_4H_8N_2}$ & -264.84232294 & -264.8423229345 & -264.8423248314\\
\hline
\end{tabular}
\label{tab:multiplicity}
\end{table}
\end{document}
答案2
解决您的问题的方法确实是\multicolumn
Niranjan 在他的回答中发布的命令。
不过我建议你做一些改变以更好地处理你的表格:
- 您可以使用
mhchem
(或其他)包。这可以帮助编写分子。 - 您还可以
siunitx
对 S 型列使用包,这可以改善数字对齐(看下面的示例)。 - 最后只是我的一个意见,但是没有垂直线的表格看起来更好。我在
booktabs
包的帮助下创建了我的表格。
这是两个表格的比较示例。我在每个表格中都添加了一行,以显示数字对齐。
\documentclass {article}
\usepackage {booktabs} % \toprule, \midrule, \cmidrule, \bottomrule
\usepackage {lipsum} % dummy text
\usepackage[version=4]{mhchem} % \ce, for writing chemistry (EDIT: ADDED version=4)
\usepackage {siunitx} % SI units, and S column type for better numbers alignment
\begin{document}
\lipsum[1]
\begin{table}[h]
\centering
\caption{Original}\label{tab:multiplicity1}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|p{2cm}||c|c|c|}
\hline
\textbf{Molecule} & \multicolumn{3}{c|}{\textbf{Ground State Energy (Hartree)}} \\
\cline{2-4}
& \textbf{Multiplicity 1} & \textbf{Multiplicity 3} & \textbf{Multiplicity 5}\\
\hline
$\mathrm{C_4H_8N_2}$ & -264.84232294 & -264.8423229345 & -264.8423248314 \\
$\mathrm{C_4H_8N_2}$ & -264.84232 & -264.842322 & -264.842324831 \\ % just to show what happens
\hline % I'm assuming the table is closed
\end{tabular}
\end{table}
\lipsum[2]
\begin{table}[h]
\centering
\caption{Suggested\strut}\label{tab:multiplicity2}
\begin{tabular}{p{2cm}S[table-format=-3.8]S[table-format=-3.10]S[table-format=-3.10]}
\toprule
\textbf{Molecule} & \multicolumn{3}{c}{\textbf{Ground State Energy (Hartree)}} \\
\cmidrule{2-4}
& {Multiplicity 1} & {Multiplicity 3} & {Multiplicity 5}\\
\midrule
\ce{C4H8N2} & -264.84232294 & -264.8423229345 & -264.8423248314 \\
\ce{C4H8N2} & -264.84232 & -264.842322 & 0.84232483 \\ % just to show what happens
\bottomrule
\end{tabular}
\end{table}
\lipsum[4]
\end{document}
编辑:我忘了添加到version=4
。mhchem
当然有一个警告。
答案3
使用包和tabularray
tlbr库,格式为“profesiona look”:mhchem
siunitx
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray} % new table
\UseTblrLibrary{siunitx} % SI units, and S column type for better numbers alignment
\usepackage[version=4]{mhchem} % \ce, for writing chemistry
\begin{document}
\begin{tblr}{hline{1,Z}=1pt, hline{3}=0.6pt,hline{2}=solid,
colspec = {l
S[table-format=-3.8]
S[table-format=-3.10]
S[table-format=-3.10]
},
row{1,2} = {font=\bfseries},
cell{1}{2} = {c=3}{c}, % multi-column, start in 1st row, 2nd column,
% span 3 columns, align center
cell{1}{1} = {r=2}{l}, % multi-row, start in 1st row, 1st column,
% span 2 rows, align center
}
Molecule & {{{Ground State Energy (Hartree)}}} && \\
& {{{Multiplicity 1}}} & {{{Multiplicity 3}}} & {{{Multiplicity 5}}} \\
\ce{C_4H_8N_2} & -264.84232294 & -264.8423229345 & -264.8423248314 \\
\ce{C_4H_8N_2} & -64.84232 & -64.842322 & -64.842324831 \\
\ce{C_4H_8N_2} & -264.842329 & -264.84232293 & -264.8423248314 \\
\end{tblr}
\end{document}