当行中任意一列出现换行文本时,tabularx 中的垂直居中标题会中断

当行中任意一列出现换行文本时,tabularx 中的垂直居中标题会中断

我有以下带有 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

在此处输入图片描述

\thead效果很好。我使用是\thead因为我希望标题行中的文本居中,中间列的内容浮动左边或者\raggedright

当我像这样\\随机断线时,问题就出现了:\thead

\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

在此处输入图片描述

第一的第二 \thead列已改变其锚点并且不再垂直居中。

你能告诉我怎样修复这个问题吗?

答案1

您实际上不需要使用\thead命令(来自makecell)。这是一个简化版本,在软件包的帮助下,对单元格中的垂直间距进行了一些改进cellspace

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

在此处输入图片描述

答案2

使用tabularray包后,您的表的代码简单而简短:

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

您可以使用 简单地将单元格中的内容分成两行(或更多行){text \\ text},对于它们的垂直居中,您只需要m在列规范中添加选项。有关语法的更多详细信息,tabularray请参阅包文档。

相关内容