如何将具有不同文本长度的乳胶表的单元格内容居中?

如何将具有不同文本长度的乳胶表的单元格内容居中?

我正在使用数组包将文本垂直居中(见下面的代码)。问题是第一列和第二列中的文本与第一列不对齐。我该如何解决这个问题?

\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{table*}
\caption{caption goes here}
\label{tab:1}       % Give a unique label    
\begin{center}
\begin{tabular}{|M{1.5cm}|M{2cm}|M{7cm}|M{1.5cm}|M{2cm}|}
\hline\noalign{\smallskip}
\multicolumn{3}{c}{text} & \multicolumn{2}{c}{text text text}\\
\noalign{\smallskip}\hline\noalign{\smallskip}   
text & text text& text text text text & text text  & text text text\\
\noalign{\smallskip}\hline\noalign{\smallskip}
text & text & {text text text text text text text text text text text text. text text text text agricultural areas around text text text text} & text & text& text\\
\rule{0pt}{5ex}
text & text & {text text text text text text text text text text text text. text text text text agricultural areas around text text text text} & text & & text& text & text\\
\rule{0pt}{5ex}
text & text & {text text text text text text text text text text text text. text text text text agricultural areas around text text text text} & text & text\\
\rule{0pt}{5ex}
text & text & {text text text text text text text text text text text text. text text text text agricultural areas around text text text text} & text & text& text\\
\noalign{\smallskip}\hline
\end{tabular}
\end{center}
\end{table*}

在此处输入图片描述

答案1

罪魁祸首是那些\rule毫无用处的命令。我还删除了那些\noalign{\smallskip}位,它们唯一的作用就是断开规则。

\documentclass{article}

\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table*}
\caption{caption goes here}
\label{tab:1}       % Give a unique label    
\centering

\begin{tabular}{|M{1.5cm}|M{2cm}|M{7cm}|M{1.5cm}|M{2cm}|}
\hline
\multicolumn{3}{c}{text} & \multicolumn{2}{c}{text text text}\\
\hline
text & text text & text text text text & text text  & text text text\\
\hline
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text \\
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text \\
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text\\
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text\\
\hline
\end{tabular}

\end{table*}

\end{document}

在此处输入图片描述

你可能想看到不同的实现:

\documentclass{article}

\usepackage{array,booktabs}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table*}
\caption{caption goes here}
\label{tab:1}       % Give a unique label    
\centering

\begin{tabular}{M{1.5cm}M{2cm}M{7cm}M{1.5cm}M{2cm}}
\toprule
\multicolumn{3}{c}{text} & \multicolumn{2}{c}{text text text}\\
\cmidrule(lr){1-3} \cmidrule(lr){4-5}
text & text text & text text text text & text text  & text text text\\
\midrule
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text \\
\addlinespace
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text \\
\addlinespace
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text\\
\addlinespace
text & text & text text text text text text text text text text text text. text text text text agricultural areas around text text text text & text & text\\
\bottomrule
\end{tabular}

\end{table*}

\end{document}

在此处输入图片描述

相关内容