前言

如题。在表格中,一个格子中文字太多,会直接溢出到文档外面… 如何自动换行,让文字合理的显示,便是本文要解决的问题。

具体流程

1)添加package (备注:在\begin{document}之前):

% for table
\usepackage{tabularx}

2)在正文中添加如下格式的表格:

\begin{table*}[!htbp]
	\centering
	\begin{tabularx}{\textwidth}{lXXX}
		\toprule
		&  \textbf{``long sentence ''} & \textbf{long sentence } & \textbf{Notes}  \\
		\midrule
		Motivation 
		& long sentence long sentence long sentence long sentence long sentence 
		& long sentence long sentence long sentence long sentence long sentence long sentence long sentencelong sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence
		& long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence long sentence 
		\\
		\midrule
		Methodology
		& 
		&
		& \\
		\bottomrule
	\end{tabularx}%
	\label{tab:addlabel}%
	\caption{A table with line breaks}
\end{table*}%

备注:关键在于:{lXXX} 以及 tabularx

显示效果如下:
在这里插入图片描述

这就看着很舒服了。

如何强制换行

基于以上代码,使用\newline就可以在表格内强制换行(而不是使用\\)。

参考文献

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐