你好,有人能告诉我如何在表格中用两行或三行写长行吗?我做了以下操作
\newline
\begin{table}[thb]
\centering
\begin{tabular}{ |p{3.5cm}||p{2cm}|p{2cm}|p{2cm}|p{2cm}| }
\hline
\multicolumn{5}{|c|}{HE} \\
\hline
parameter&\multicolumn{2}{c|}{X} &\multicolumn{2}{c|}{Y}\\
\hline
& \makecell{A} & \makecell{D} &\makecell{A} & \makecell{B}\\
\hline
comment &short line &h_2, N_2, CO_2, CO, H_2O, MeOH &_2, N_2, CO_2, CO, H_2O, MeOH\\
Phase& Shortline & This is very long line & This is very long line &This is very long line\\
\hline
\end{tabular}
\caption{caption}
\label{tab:my_label}
\end{table}
答案1
为了正确排版化学式,我使用了该chemmacros
包。为了避免由于p
类型列默认对齐而引入的大空白,我将第 3 列和第 4 列的内容左对齐。为此,您可以在>{\raggedright\arraybackslash}
要左对齐的列的列说明符前面添加,也可以定义一个新列,就像我对第四列所做的那样:
\documentclass{article}
\usepackage{makecell}
\usepackage{chemmacros} % Provides the \ch command
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{table}[thb]
\centering
\begin{tabular}{ |p{3.5cm}||p{2cm}|>{\raggedright\arraybackslash}p{2cm}|R{2cm}|p{2cm}| }
\hline
\multicolumn{5}{|c|}{HE} \\
\hline
parameter&\multicolumn{2}{c|}{X} &\multicolumn{2}{c|}{Y}\\
\hline
& \makecell{A} & \makecell{D} &\makecell{A} & \makecell{B}\\
\hline
comment &short line & \ch{H2}, \ch{N2}, \ch{CO2}, \ch{CO}, \ch{H2O}, \ch{MeOH} & \ch{H2}, \ch{N2}, \ch{CO2}, \ch{CO}, \ch{H2O}, \ch{MeOH} &\\
Phase& Shortline & This is very long line & This is very long line &This is very long line\\
\hline
\end{tabular}
\caption{caption}
\label{tab:my_label}
\end{table}
\end{document}
答案2
我把我的答案限制在包含化学式的那一行,这似乎是最麻烦的部分——我认为第四列内容的开头也缺少了一些东西{_2, N_2, CO_2, CO, H_2O, MeOH}
请注意,您添加了一个未使用的附加列
添加\usepackage{chemfig}
序言
\begin{table}
\centering
\begin{tabular}{ |p{3.5cm}||p{2cm}|l|l|p{2cm}| }
comment &short line & \chemfig{h_2, N_2, CO_2, CO, H_2O, MeOH} &
\chemfig{_2, N_2, CO_2, CO, H_2O, MeOH}\\
\end{tabular}
\caption{caption}
\label{tab:my_label}
\end{table}