如何垂直對齊表格中的文本

如何垂直對齊表格中的文本

我在垂直對齊表格中的文字時遇到問題。

我這樣定義新的列類型:

\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.25\linewidth-2\tabcolsep}}

這適用於除最後一列之外的所有列。知道為什麼最後一個不起作用嗎?

第二個問題:多列行中的文字如何垂直對齊?

這是我的程式碼的完整範例。

\documentclass[aps,pre,superscriptaddress,unsortedaddress,twocolumn,showpacs]{revtex4}

\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{threeparttable} 
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.25\linewidth-2\tabcolsep}}



\begin{document}
\begin{table}[!htp]
\begin{threeparttable}
\caption{Summary.} {\small\label{table:S2}}\centering 
\small
\begin{tabularx}{\textwidth}{ |X|M|M| }


\multicolumn{3}{M}{LONG TEXT}\\[4ex]\hline
      &  text         &   text \\\hline
text  &  complex text & complex text \\[6ex]\hline
text  &  complex text &  complex text   \\[6ex]\hline
text  & complex text  & complex text  \\[6ex]\hline

\multicolumn{3}{M}{LONG TEXT}  \\[4ex]\hline
     & text            &  text  \\\hline
text &  complex text   & complex text \\[6ex]\hline
text & complex text    & complex text   \\[6ex]\hline
text &   complex text  & complex text \\[6ex]\hline


  \hline
  \end{tabularx}
    \end{threeparttable}
\end{table}

\end{document}

非常感謝你的幫忙!

答案1

我認為你可以使用以下方法簡化你的程式碼tabularray

\documentclass[aps,pre,superscriptaddress,unsortedaddress,twocolumn,showpacs]{revtex4}

\usepackage{tabularray}

\begin{document}
\begin{table}[!htp]
    \caption{Summary.}\label{table:S2}
    \begin{tblr}{
        width=\linewidth,
        colspec={X[2]X[c]X[c]},
        hline{2-Z}={solid},
        vline{1-Z}={2-5, 7-Z}{solid},
        row{1,6}={ht=4ex},
        row{3-5,8-Z}={ht=6ex},
        row{2,7}={abovesep=1ex},
        row{1,6}={abovesep=2ex},
        }
        \SetCell[c=3]{c} LONG TEXT & & \\     
        & text & text \\
        text & complex text & complex text \\
        text & complex text & complex text \\
        text & complex text & complex text \\
        \SetCell[c=3]{c} LONG TEXT & & \\
        & text & text \\
        text & complex text & complex text \\
        text & complex text & complex text \\
        text & complex text & complex text 
    \end{tblr}
\end{table}
\end{document}

在此輸入影像描述

相關內容