我正在尝试创建一个有机化合物列表作为表格的一部分。但是,当我将 chemfig 元素添加到表格中时,它们会接触到单元格的顶部和底部,这是不希望的。此外,较长的链会延伸到单元格的宽度之外。有什么想法吗?
\begin{table}[H]
\centering
\begin{tabular}{|c|c|p{0.2\textwidth}|c|}
\hline
IUPAC Name & Formula & Line Diagram & Molar Mass ($\frac{g}{mol}$) \\
\hhline{|====|}
Methanol & $CH_3OH_{(g)}$ & \chemfig{H-C(-[2]H)(-[6]H)-O(-[6]H)} & 32.04 \\
\hline
Ethanol & $C_2H_5OH_{(g)}$ & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 46.07 \\
\hline
2-methylpropan-1-ol & $C_4H_9OH_{(g)}$ & SOON & 74.12 \\
\hline
Butan-1-ol & $C_4H_9OH_{(g)}$ & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 74.12 \\
\hline
3-methylbutan-1-ol & $C_5H_{11}OH_{(g)}$ & SOON & 88.15 \\
\hline
Pentan-1-ol & $C_5H_{11}OH_{(g)}$ & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 88.15 \\
\hline
\end{tabular}
\end{table}
答案1
不要修复化学图片。相反,修复水平线,即\hline
用包的线条绘制宏替换基本宏,booktabs
以获得间距良好的水平线。具体来说,我建议您将内部\hline
指令替换为\addlinespace[3mm]
整个指令。空白可以像实线一样成为视觉障碍。哦,去掉垂直线:它们是不需要的,而且不会被遗漏。
\documentclass{article} % or some other suitable document class
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters as needed
\usepackage{chemfig} % for \chemfig macro
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{mhchem} % for \ce macro
\usepackage{siunitx} % for \unit macro
\begin{document}
\begin{table}[ht!]
\centering
\begin{tabular}{@{} l c c c @{}}
\toprule
IUPAC Name & Formula & Line Diagram & Molar Mass \\
& & & (\unit[per-mode=symbol]{\gram\per\mol}) \\
\midrule
Methanol & \ce{CH3OH_{(g)}} & \chemfig{H-C(-[2]H)(-[6]H)-O(-[6]H)} & 32.04 \\
\addlinespace[3mm]
Ethanol & \ce{C2H5OH_{(g)}} & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 46.07 \\
\addlinespace[3mm]
2-methylpropan-1-ol & \ce{C4H9OH_{(g)}} & SOON & 74.12 \\
\midrule
Butan-1-ol & \ce{C4H9OH_{(g)}} & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 74.12 \\
\addlinespace[3mm]
3-methylbutan-1-ol & \ce{C5H11OH_{(g)}} & SOON & 88.15 \\
\addlinespace[3mm]
Pentan-1-ol & \ce{C5H11OH_{(g)}} & \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)} & 88.15 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我会做出一些改变:
- 旋转表格以垂直呈现它并为图形留出更多空间;
使用sidewaystable
env. 可能是最方便的方法 - 将固定列 p{} 更改为常规列 sa 'l'
- 摆脱垂直条
- (可选)从中添加自定义规则
booktabs
。
上述变化改善了表格,但有些数字可能仍然太接近。
如果您决定在booktabs
每行之间插入水平线,这些线将添加小间隙,其大小存储在和中\aboverulesep
。\belowrulesep
以下是演示此方法的代码
\documentclass{article}
\usepackage{chemfig}
\usepackage{booktabs}
\usepackage{rotating}
\setlength\aboverulesep{4pt}
\setlength\belowrulesep{4pt}
\begin{document}
\begin{sidewaystable}
\centering
\begin{tabular}{c c l c c}
\toprule
IUPAC Name
& Formula
& Line Diagram
& Molar Mass ($\frac{g}{mol}$) \\
\midrule
Methanol
& $CH_3OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)-O(-[6]H)}
& 32.04 \\
\midrule
Ethanol
& $C_2H_5OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)}
& 46.07 \\
\midrule
2-methylpropan-1-ol
& $C_4H_9OH_{(g)}$
& SOON
& 74.12 \\
\midrule
Butan-1-ol
& $C_4H_9OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-O(-[6]H)}
& 74.12 \\
\midrule
3-methylbutan-1-ol
& $C_5H_{11}OH_{(g)}$
& SOON
& 88.15 \\
\midrule
Pentan-1-ol
& $C_5H_{11}OH_{(g)}$
& \chemfig{
H-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-O(-[6]H)}
& 88.15 \\
\bottomrule
\end{tabular}
\end{sidewaystable}
\end{document}
另一方面,您也可以通过cellspace
包强制单元格的顶部和底部间距。这些由包中的另外两个长度名称控制:\cellspacetoplimit
和\cellspacebottomlimit
(参见下面的代码)。表格将对Sx
列应用最小间隙,其中x
可以是l
、、c
等r
,p{}
具体取决于水平对齐和宽度。
该示例基于cellspaces
:
\documentclass{article}
\usepackage{chemfig}
\usepackage{rotating}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
\begin{sidewaystable}
\renewcommand{\arraystretch}{1.25}
\centering
\begin{tabular}{c c Sl c c}
\hline
IUPAC Name
& Formula
& Line Diagram
& Molar Mass ($\frac{g}{mol}$) \\
\hline
Methanol
& $CH_3OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)-O(-[6]H)}
& 32.04 \\
Ethanol
& $C_2H_5OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O(-[6]H)}
& 46.07 \\
2-methylpropan-1-ol
& $C_4H_9OH_{(g)}$
& SOON
& 74.12 \\
Butan-1-ol
& $C_4H_9OH_{(g)}$
& \chemfig{H-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-O(-[6]H)}
& 74.12 \\
3-methylbutan-1-ol
& $C_5H_{11}OH_{(g)}$
& SOON
& 88.15 \\
Pentan-1-ol
& $C_5H_{11}OH_{(g)}$
& \chemfig{
H-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)
-O(-[6]H)}
& 88.15 \\
\hline
\end{tabular}
\end{sidewaystable}
\end{document}