0

I have problems vertically aligning text in my table.

I define new column type like this:

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

And this works for all column but last one. Any idea why doesn't it work for the last one?

The second question: how to vertically align text in multi-column rows?

Here is the whole example of my code.

\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}

Thanks a lot for your help!!!

4
  • 1
    I don't succeed in compiling your example: ! Package array Error: Illegal pream-token (D): `c' used. ...... l.33 \end{tabularx}
    – Joachim W
    Commented Apr 23, 2015 at 17:03
  • 1
    D is an unknown (to me) column type
    – user31729
    Commented Apr 23, 2015 at 17:05
  • 1
    I suspect that the \\[6ex] screws up the vertical spacings for vertical centering of that M columns
    – user31729
    Commented Apr 23, 2015 at 17:12
  • sorry, D was there by mistake. I changed it.
    – ana
    Commented Apr 24, 2015 at 6:46

1 Answer 1

2

I think you can simplify your code using 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}

enter image description here

4
  • I cant compile your MWE. Error: Missing \begin{document}. I guess that is caused by used document class (is it obsolete as far as I know)`.
    – Zarko
    Commented Apr 18, 2022 at 17:32
  • @Zarko I compiled it with an updated version of TeX Live 2022, with no errors.
    – CarLaTeX
    Commented Apr 18, 2022 at 19:32
  • I test with recent version of MiKTEX. I also try with Overleaf, but it still use TeX Live 2021, which use "ancient" tabularray package. Your proposition work fine with article! +1 1 for nice answer!
    – Zarko
    Commented Apr 18, 2022 at 19:39
  • @Zarko With Overleaf, with TeX Live 2021, you can't use Z in hline, vline, and row options. If you substitute it with a number, it works also with Overleaf. I think it is a new feature of tabularray. Thank you for the +1.
    – CarLaTeX
    Commented Apr 18, 2022 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .