前言
如题。在表格中,一个格子中文字太多,会直接溢出到文档外面… 如何自动换行,让文字合理的显示,便是本文要解决的问题。
具体流程
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
就可以在表格内强制换行(而不是使用\\
)。