0

I am using tabularx environment and in the MWE I have three columns. The first column contains short text, the second column contains long text and the third column contains short text again.

\documentclass{article}    
\usepackage{tabularx}

\begin{document}

\begin{tabularx}{6cm}{|p{2cm}|b{2cm}|p{2cm}|} 
short 1 & long text spanning more than one row & short 2 \\
\end{tabularx}

\end{document}

As expected, the result is that both short 1 and short 2 align to the bottom.

enter image description here

If I change the setting on middle column from b{2cm} to p{cm}, as expected both short 1 and short 2 align to the top.

I would like to make short 1 align to the top and short 2 align to the bottom. How can I achieve that?

Thanks in advance.

EDIT:

Following the suggestion by @NBur who pointed me out to this post, I've implemented the following changes:

\documentclass{article}    
\usepackage{tabularx}

\newcolumntype{C}{b{2cm}<{\vfill}}

\begin{document}


\begin{tabularx}{6cm}{|C|b{2cm}|p{2cm}|} 
short 1 & long text spanning more than one row & short 2 \\
\end{tabularx}

\end{document}

Unfortunately this code brings up the text only by one line and not all the way up to the top of the cell, so it does not work.

enter image description here

Are there any other suggestions?

6
  • 5
    Does this answer your question? Different vertical alignment of text in 4-column table (tabularx)
    – NBur
    Commented Feb 5, 2021 at 17:08
  • apart from the alignment you should use tabular not tabularx here as all the columns are p not X Commented Feb 5, 2021 at 18:19
  • @NBur, thank you for your reply. However, following the instruction /vfill brings up the text in the cell only by one line, not all the way to the top. Do you have any other suggestion? Maybe using some kind of a box?
    – jopeto
    Commented Feb 7, 2021 at 6:42
  • @DavidCarlisle, I need to use tabularx for my table, I have just stripped down all the unnecessary parts for the purpose of MWE.
    – jopeto
    Commented Feb 7, 2021 at 6:44
  • It seems to me the same problem as in this post and I think the same solution can be used. Commented Feb 7, 2021 at 19:14

1 Answer 1

1

It is very simple to achieve with the new package tabularray:

\documentclass{article}    
\usepackage{tabularray}
\begin{document}
\begin{tblr}{|Q[h,2cm]|Q[m,2cm]|Q[f,2cm]|}
short 1 & long text spanning more than one row & short 2 \\
\end{tblr}

\vspace{1cm}
And if you like the second column be justified:
\vspace{1cm}

\begin{tblr}{|Q[h,2cm]|Q[m,2cm,halign=j]|Q[f,2cm]|}
short 1 & long text spanning more than one row & short 2 \\
\end{tblr}

\end{document}

enter image description here

You must log in to answer this question.

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