如何停止对齐单元格内容并水平左对齐、垂直中间对齐?

如何停止对齐单元格内容并水平左对齐、垂直中间对齐?

正如您在图片上看到的,左列的内容是对齐的,因此在内容之间添加了不均匀的间距。我试图让左列的内容垂直居中,水平向左。

在此处输入图片描述

我尝试添加\begin{tabular}{>{\RaggedRight}m{3.7cm} m{5cm}以下脚本,但没有效果。

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\begin{table}
\begin{tabular}{m{3.7cm}| m{5cm}}
\toprule
Sample1                            & Sample2      \\  \midrule
AB\_CDEFG and AB\_CDE       & This is sample text.This is sample text. This is sample text. This is sample text. This is sample text.  This is sample text.This is sample text. This is sample text. This is sample text. This is sample text.\\ \midrule
AB\_CD, AB\_CD,AB\_CD and AB\_CD   &  This is sample text.This is sample text. This is sample text. This is sample text. This is sample text. This is sample text.This is sample text. This is sample text. This is sample text. This is sample text.\\ \bottomrule
\end{tabular}
\label{table:referent-table}
\end{table}
\end{document}

感谢您对如何实现这一目标的建议。

答案1

您可以加载ragged2e包并使用其\RaggedRight指令来实现格式化目标。在此过程中,您也可以将其应用于\RaggedRight第二列。

请注意,\RaggedRight允许在单元格中使用连字符。如果您还想禁止使用连字符,只需更改\RaggedRight\raggedright\arraybackslash

在此处输入图片描述

附言:我禁不住对流经右侧单元格的印刷河流赞叹不已。:-)

\documentclass{article}
\usepackage{array,booktabs,ragged2e}
\begin{document}

\begin{table}
\caption{Example of a table\strut} 
\label{table:referent-table}

\centering % <-- don't forget this instruction

\begin{tabular}{@{} >{\RaggedRight}m{3.7cm} >{\RaggedRight}m{5.0cm} @{}}
\toprule
Sample1 & Sample2 \\  
\midrule
AB\_CDE, AB\_CDE and AB\_CDE       
& This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. \\ 
\midrule
AB\_CD, AB\_CD, AB\_CD and AB\_CD   
& This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. \\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}

相关内容