0

I have the following long table with tabularx.

\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{tabularx}{\textwidth}{|>{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}X|
    >{\hsize=.5\hsize\raggedright\let\newline\\\arraybackslash}X|
    >{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}X|}
    \hline
    \thead{Thời gian}
    & \thead{Công việc}
    & \thead{Người thực hiện}
    \\
    \hline
    x/x/xx
    \newline
    -
    \newline
    x/x/xx
    &
    - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
    \newline
    - Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    &
    Lorem Ipsum is simply dummy
    \\
    \hline

enter image description here

\thead worked pretty well. I used \thead because I want texts in the header row centered and the content of the middle column to float left or \raggedright.

The problem comes here when I breaking line \\ to a random \thead like this:

\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{tabularx}{\textwidth}{|>{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}X|
    >{\hsize=.5\hsize\raggedright\let\newline\\\arraybackslash}X|
    >{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}X|}
    \hline
    \thead{Thời gian}
    & \thead{Công việc}
    & \thead{Người \\ thực hiện}
    \\
    \hline
    x/x/xx
    \newline
    -
    \newline
    x/x/xx
    &
    - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
    \newline
    - Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    &
    Lorem Ipsum is simply dummy
    \\
    \hline

enter image description here

The FIRST and SECOND \thead column have changed their anchor and do not center veticaly anymore.

Can you show me how to fix this?

4
  • X uses p columns so aligns on the first line you can define it to use m columns using \tabularxcolumn you have not shown how you have defined \thead nor provided a test document Commented Aug 27, 2022 at 17:17
  • Thank you, I'm being new to Latex. Can you show me the code of define m columns using \tabularxcolumn ? And I have used the usual \thead, so I do not define any on it yet.
    – Huy Pham
    Commented Aug 27, 2022 at 17:54
  • there is no "usual" \thead tabularx defines no command of that name. \renewcommand\tabularxcolumn#1{m{#1}} would make tabularx use m columns Commented Aug 27, 2022 at 17:57
  • Sorry, my bad. I forgot that I had defined the command. There is my command \renewcommand\tabularxcolumn[1]{m{#1}}
    – Huy Pham
    Commented Aug 27, 2022 at 18:04

2 Answers 2

3

You don't really need to use the \thead command (from makecell). Here is a simplified version, and some improvements as to vertical spacing in cells, with the help of the cellspace package:

    \documentclass{article}
    \usepackage[vietnamese]{babel}
    \usepackage{tabularx}
    \usepackage{cellspace}
    \setlength{\cellspacetoplimit}{4pt}
    \setlength{\cellspacebottomlimit}{4pt}
    \addparagraphcolumntypes{X}
    \renewcommand\tabularxcolumn[1]{m{#1}}

    \begin{document}

        \begin{tabularx}{\textwidth}{|>{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}X|
            >{\hsize=.5\hsize\raggedright\let\newline\\\arraybackslash}X|
            >{\hsize=.25\hsize\centering\let\newline\\\arraybackslash}S{X}|}
            \hline
            Thời gian
            & Công việc
            & Người \newline thực hiện
            \\
            \hline
        \end{tabularx}

    \end{document} 

enter image description here

2
  • I have tried this before, but it's not for my case. The problem is I want the text in the header row centered and the content of middle column to float left or \raggedright. I used \thead because it has \textbf and center the text.
    – Huy Pham
    Commented Aug 28, 2022 at 19:58
  • @HuyPham: but you have >{\raggedright} for the second column. If you also want the second column head centred, replace \raggedright} with >{\centering}.
    – Bernard
    Commented Aug 28, 2022 at 20:50
0

With tabularray package the code for your table is simple and short:

\documentclass{article}
\usepackage[vietnamese]{babel}
\usepackage{tabularray}

\begin{document}

\noindent%2,
\begin{tblr}{hlines, vlines,
             colspec = {X[1, c,m] X[2,r,m] X[1,c,m]},
             rowsep  = 4pt,
             row{1}  = {font=\bfseries}
             }
Thời gian   & Công việc & {Người\\ thực hiện}   \\
\end{tblr}

\end{document}

Contents in cells you can simply split in two (or more) lines with {text \\ text}, for vertical center of them, you only needs to add option m to column specification. For more details of tabularray syntax see package documentation.

You must log in to answer this question.

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