可能重复:
如何在表格单元格内添加强制换行符
我想在多行上写列标题。我尝试了以下命令,但不起作用:
\begin{tabular}{|c|l|l|l|l|l|l|}
\hline \\
$\alpha$
& \multicolumn{1}{|c|}{GallusGallus \\ CC \\ t = 104}
& \multicolumn{1}{|c|}{GallusGallus \\ MF \\ t = 124}
& \multicolumn{1}{|c|}{GallusGallus \\ BP \\ t = 110}
& \multicolumn{1}{|c|}{BosTaurus \\ CC \\ t = 99}
& \multicolumn{1}{|c|}{BosTaurus \\ MF \\ t = 217}
& \multicolumn{1}{|c|}{BosTaurus \\ BP \\ t = 205}
\end{tabular}
我该如何修复?
答案1
您可以使用P{<width>}{<contents>}
而不是使用c
column。在p
(段落)列中,通常\centering
可以使用 column 来将内容居中。
\documentclass{article}
\begin{document}
\begin{tabular}{|c|l|}
\hline
$\alpha$
& \multicolumn{1}{|p{3cm}|}{\centering GallusGallus \\ CC \\ t = 104}\\\hline
\end{tabular}
\end{document}
完整示例如下:
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\noindent
\begin{tabular}{|c|l|l|l|l|l|l|}
\hline
$\alpha$
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ CC \\ t = 104}
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ MF \\ t = 124}
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ BP \\ t = 110}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ CC \\ t = 99}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ MF \\ t = 217}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ BP \\ t = 205}\\\hline
\end{tabular}
\end{document}