问题描述
使用latex绘制表格时,有时候会遇到单元格的文字过长,显得很拥挤,适当的换行可以使整体效果更加美观,比如:
源代码为:
\resizebox{\textwidth}{!}{
\begin{tabular}{cccccccc}
\toprule
\textbf{Name} & \textbf{Student Number} &\textbf{Gender} &\textbf{Program Duration} & \textbf{Enrollment Date}
&\textbf{Education Date} &\textbf{major} &\textbf{Schooling} \\
\hline
\end{tabular}
效果:
文字过于紧凑,显得很小,有两个单词的容易引起混淆
解决
- 调用包usepackage{makecell}
- 在需要换行的文字上添加\makecell,并在换行处使用 “\\” , 比如demo中的“Student Number”, 可以写为\makecell{Student \\ Number}
调整后:
\resizebox{\textwidth}{!}{
\begin{tabular}{cccccccc}
\toprule
\textbf{Name} & \textbf{\makecell{Student \\ Number}} &\textbf{Gender} &\textbf{\makecell{Program \\ Duration}} & \textbf{\makecell{Enrollment \\ Date}}
&\textbf{\makecell{Education \\ Date}} &\textbf{major} &\textbf{Schooling} \\
\hline
\end{tabular}
}