latex 表格 调整单元格文本垂直居中

在撰写论文时,常常使用table制作表格,不过存在一个问题:单元格内文本顶着上格线,不好看。解决方案有两种思路。

其一:利用multicolumn命令

制作四行四列表格的代码如下:

\begin{center}

\begin{tabular}{ | l | l | l | p{5cm} |}

\hline

Day & Min Temp & Max Temp & Summary \\

\hline

Monday & 11C & 22C & A clear day with lots of sunshine. However, the strong breeze will bring down the temperatures. \\

\hline

Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\

\hline

Wednesday & 10C & 21C & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\

\hline

\end{tabular}

\end{center}

生成的表格如下:

latex 表格 调整单元格文本垂直居中_第1张图片

能看到单元格文字靠近上格线。这里我们需要修改一下命令

主要添加了multicolumn命令,其中

m{5cm}:居中

p{5cm}:顶部

b{5cm}:底部

************************************

\begin{center}

\begin{tabular}{|l|l|l|l|}

\hline

Day & Min Temp & Max Temp & Summary \\

\hline

Monday & 11C & 22C & \multicolumn{1}{|p{5cm}|}{A clear day with lots of sunshine. However, the strong breeze will bring down the temperatures.} \\

\hline

Tuesday & 9C & 19C & \multicolumn{1}{|m{5cm}|}{Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest.} \

\hline

Wednesday & 10C & 21C & \multicolumn{1}{|b{5cm}|}{Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening.} \\

\hline

\end{tabular}

\end{center}

生成的表格如下:

latex 表格 调整单元格文本垂直居中_第2张图片

这种思路设计起来挺麻烦,如果心细,可以做一做。

其二:单元格内容纵向靠上对齐,表线距单元格内容太近。调整表线和单元格内容之间的距离,可以通过重定义 \arraystretch 来解决。

\renewcommand{\arrarstretch}{} % default is 1.0

latex 表格 调整单元格文本垂直居中_第3张图片

 感觉这个比较好用,但是这个也是针对每个单元格是单行文本时,才好用。如果单元格是多行文本,则需要使用方法一比较好点。

 参考:https://www.zhihu.com/question/288695777/answer/462924502

你可能感兴趣的:(基本技能)