![如何在表格单元格中创建新行](https://linux22.com/image/292223/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E5%88%9B%E5%BB%BA%E6%96%B0%E8%A1%8C.png)
我正在尝试创建一个表格,但是表格单元格中的内容很长,因此我决定为单元格创建一个新行。
但我不知道该怎么做,有人能帮我吗?这是我的代码:
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & Likelihood (Limnodynastes peronii Distribution Model) &Likelihood (Rhinella marina Distribution Model)\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
答案1
可能的解决方案之一是使用\multicolumn
适当的参数。第二列中的线条是手动断开的,第三列中的线条是自动断开的,这看起来不太好看。但是,总体思路应该很清楚。应该p{4cm}
用更合适的值替换。
\documentclass{article}
\begin{document
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & \multicolumn{1}{p{4cm}|}{Likelihood\newline (Limnodynastes peronii\newline Distribution Model) } &\multicolumn{1}{p{4cm}|}{Likelihood (Rhinella marina Distribution Model)}\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & Likelihood (Limnodynastes peronii Distribution Model) &Likelihood (Rhinella marina Distribution Model)\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
答案2
另一种选择是使用堆栈,我展示了您的表格两次以显示可能的多样性。在第一个表中,堆栈是顶部对齐的(\Longunderstack
s),而在第二个表中,它们是垂直居中的(\Centerstack
s)。在第一个表中,它们是水平居中的,而在第二个表中,它们是左对齐的。
tabular
在输入之前,即\edef\tmp{\the\baselineskip}\setstackgap{L}{\tmp}
在中使用堆栈时,需要两行“设置”行tabular
,因为tabular
重新定义了\baselineskip
,这是长堆栈的默认基线间距。
\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\edef\tmp{\the\baselineskip}
\setstackgap{L}{\tmp}
\begin{document}
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & \Longunderstack{Likelihood\\
(Limnodynastes peronii\\ Distribution Model)} &
\Longunderstack{Likelihood\\ (Rhinella marina \\Distribution Model)}\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\leavevmode\bigskip\\
\begin{tabular}{ |c|c|c| }
\hline
Observation(Species name) & \Centerstack[l]{Likelihood\\
(Limnodynastes peronii\\ Distribution Model)} &
\Centerstack[l]{Likelihood\\ (Rhinella marina \\Distribution Model)}\\
\hline
Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
\hline
Observation 2 (Rhinella marina) &0.30 &0.013 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}