![表格内对齐无法与段落配合使用吗?](https://linux22.com/image/361694/%E8%A1%A8%E6%A0%BC%E5%86%85%E5%AF%B9%E9%BD%90%E6%97%A0%E6%B3%95%E4%B8%8E%E6%AE%B5%E8%90%BD%E9%85%8D%E5%90%88%E4%BD%BF%E7%94%A8%E5%90%97%EF%BC%9F.png)
我一直在使用表格,我想让每个单元格有 4 行,而一列对齐以对齐方程式。这是我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}
\begin{tabular}{|p{4cm}|c|}
\hline
Acid & Ionization in Water \\
\hline
Hydrochloric acid\\
Nitric acid\\
Nitrous acid\\
Ethanoic acid
&
$\begin{aligned}[t]
\text{HCI(aq)} & \rightarrow \text{H}^+\text{(aq)}+\text{CI}^-\text{(aq)}\\
\text{HNO}_3\text{(aq)} & \rightarrow \text{H}^+\text{(aq)}+\text{NO}^-_3\text{(aq)} \\
\text{HNO}_2\text{(aq)} & \rightleftharpoons \text{H}^+\text{(aq)}+\text{NO}^-_2\text{(aq)} \\
\text{CH}_3\text{COOH(aq)} & \rightleftharpoons \text{H}^+\text{(aq)}+\text{CH}_3\text{COO}^-\text{(aq)}
\end{aligned}$
\end{tabular}
\end{table}
\end{document}
但结果并不是我想要的,而是这样的:
似乎对齐位于段落的最后一行。有人能帮忙吗?
答案1
我认为你正在寻找这样的东西:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{chemformula}
\setchemformula{charge-hshift=.5pt}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.5}
\usepackage{booktabs}
\usepackage{caption}
\begin{document}
\begin{table}
\caption{Look as your original table}
\begin{tabular}{|p{4cm}|r@{}c@{}l|}
\hline
Acid & \multicolumn{3}{c|}{Ionization in Water} \\
\hline
Hydrochloric acid &
\ch{HCI(aq)} & \ch{->} & \ch{H^+(aq) + CI^-(aq)}\\
Nitric acid &
\ch{HNO3(aq)} & \ch{->} & \ch{H^+(aq) + NO^-_3(aq)} \\
Nitrous acid &
\ch{HNO2(aq)} & \ch{<=>} &\ch{H^+(aq) + NO^-_2(aq)} \\
Ethanoic acid & \ch{CH_3COOH(aq)} & \ch{<=>} & \ch{H^+(aq) + CH_3COO^-(aq)}
\end{tabular}
\end{table}
However, I also suggest to you to use \texttt{booktabs} and get rid of
vertical rules, as in Table \ref{tab:book}.
\renewcommand{\arraystretch}{1.2}
\begin{table}
\caption{Look with \texttt{booktabs}\label{tab:book}}
\begin{tabular}{p{4cm}r@{}c@{}l}
\toprule
Acid & \multicolumn{3}{c}{Ionization in Water} \\
\midrule
Hydrochloric acid &
\ch{HCI(aq)} & \ch{->} & \ch{H^+(aq) + CI^-(aq)}\\
Nitric acid &
\ch{HNO3(aq)} & \ch{->} & \ch{H^+(aq) + NO^-_3(aq)} \\
Nitrous acid &
\ch{HNO2(aq)} & \ch{<=>} &\ch{H^+(aq) + NO^-_2(aq)} \\
Ethanoic acid & \ch{CH_3COOH(aq)} & \ch{<=>} & \ch{H^+(aq) + CH_3COO^-(aq)}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
我还建议您使用chemformula
包装,我不是化学家,但正如您所见,它简化了很多公式。booktabs
包装可以让您的表格看起来更好。
答案2
这是另一种解决方案,它摒弃了环境aligned
,而是利用了化学工程mhchem
包来排版化学式。(和包的语法要求chemformulas
非常相似。)
我还想建议您通过删除所有垂直线并使用包的线条绘制宏来使表格看起来“开放” booktabs
。我还会使用Cl
而不是CI
来表示氯。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mhchem,booktabs}
\begin{document}
\begin{table}
\renewcommand\arraystretch{1.25} % 1.5 seems excessive
\centering
\begin{tabular}{@{} l r@{}c@{}l @{}}
\toprule
Acid & \multicolumn{3}{c@{}}{Ionization in Water} \\
\midrule
Hydrochloric acid &
\ce{HCl(aq)} & \ce{->} & \ce{H+(aq) + Cl-(aq)} \\
Nitric acid &
\ce{HNO3(aq)} & \ce{->} & \ce{H+(aq) + NO3-(aq)} \\
Nitrous acid &
\ce{HNO2(aq)} & \ce{<=>} & \ce{H+(aq) + NO2-(aq)} \\
Ethanoic acid &
\ce{CH3COOH(aq)} & \ce{<=>} & \ce{H+(aq) + CH3COO-(aq)} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
您可以使用aligned
以下简单的语法来表示化学反应chemformula
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow,bigstrut, makecell}
\usepackage{amsmath}
\usepackage{array}
\usepackage{chemformula}
\renewcommand{\arraystretch}{1.5}
\renewcommand{\cellset}{\renewcommand{\arraystretch}{1.25}}
\begin{document}
\begin{table}
\begin{tabular}{|p{4cm}|c|}
\hline
Acid & Ionization in Water \\
\hline
\makecell[lt]{Hydrochloric acid \\
Nitric acid \\
Nitrous acid \\
Ethanoic acid\bigstrut[b]}
&
$\begin{aligned}[t]
\ch{HCI (aq) & -> H+ (aq) + CI- (aq) \\
HNO (aq) & -> H+ (aq) + NO3- (aq) \\
HNO2 (aq) & <=> H+ (aq) + NO2- (aq) \\
CH3COOH (aq) & <=>H+ (aq) + CH3COO- (aq)}
\end{aligned}$ \\%
\hline
\end{tabular}
\end{table}
\end{document}