优雅解决LATEX中\multirow及\multicolumn的单元格的居中及换行问题 您所在的位置:网站首页 如何在表格内容居中 优雅解决LATEX中\multirow及\multicolumn的单元格的居中及换行问题

优雅解决LATEX中\multirow及\multicolumn的单元格的居中及换行问题

2024-07-17 19:55| 来源: 网络整理| 查看: 265

首先解释一下Mr-Cat伍可猫为何会遇到这个问题

\centering在复合列multicolumn中直接使用有时候是无效的。

\multirow以及\multicolumn自从latex2.0后只接收10进制的line调整,所以我们需要手动调整具体的位置。

在不设置parbox的情况下,multirow的宽带会自动调整,而其高度会默认为最小

这是一个既垂直居中,同时也是水平居中,同时还有不居中的例子:

\renewcommand\arraystretch{1.5} \newcolumntype{Y}{>{\centering\arraybackslash}X} \begin{table}[t] \caption{Caption.} \label{table:label} \begin{tabularx}{\columnwidth}{| Y | Y | X | X |} \hline & Test & Test & Time [minutes] \\ \hline \multirow{2}{*}{A} & \multirow{2}{*}{100\%} & 100\% & x \\ \cline{3-4} & & 100\% & y \\ \hline \multirow{2}{*}[-6pt]{B} & & 100\% & 100\% \\ % ---> [-6pt] \cline{3-3} & 100\% & Success rate: 100\% & \\ \hline \end{tabularx} \end{table}

在这里插入图片描述 latex本身就是一种解释型语言,所以我们可以定义单元格中的字段,并使用X以及Y进行指代,\newcolumntype{Y}{>{\centering\arraybackslash}X}则定义Y为垂直+水平居中,而X则为普通格式。

但是实际写表格的时候,有时候我们会在其中加入大量的语句用于说明,这时候就不可避免的遇到换行的问题。很多博客提出了不少解决方案,但都只是针对单纯的len进行换行。而对于multirow,一般是不适用的。

主要原因是multirow这一命令在调用的过程中会重新定义宽,高以及文格式。

单纯在\begin{tabular}旁边使用{p{0.3\textwidth}booktabs}% http://ctan.org/pkg/booktabs \usepackage{multirow} \usepackage{array} \begin{document} \noindent \begin{table*} \begin{tabular}% {>{\centering\arraybackslash}p{0.3\textwidth}% >{\centering\arraybackslash}p{0.3\textwidth}% >{\centering\arraybackslash}p{0.3\textwidth}} \toprule \multirow{2}{0.3\textwidth}{\centering On the other hand, cloud-based IoT has also provided a convincing platform to guarantee distributed location-based service (LBS) by periodically collecting and broadcasting certain kinds of passing service information such as all the restaurants satisfying the user's query conditions in the neighborhood and the traffic conditions for specific road sections during required time periods. } & \multicolumn{2}{c}{Logic of rule adoption} \\[21ex] \cmidrule{2-3} & Logic of consequences & Logic of appropriateness \\ \midrule EU-driven & External incentives model & Social learning model \\ CEE-driven & Lesson-drawing model & Lesson-drawing model \\ \bottomrule \end{tabular} \end{table*} \end{document}

实际效果: 在这里插入图片描述

Tips: 1.如果只想要单独的单元格水平居中,使用\multicolumn{1}{c}{content} 即可。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有