tabularx 中的中心列内容

tabularx 中的中心列内容

我使用创建了一个表格,tabularx但似乎无法将文本置于列的中心。我尝试使用“X”和“c”(适用于表格),但似乎不起作用。有人能给我一些建议吗?我也不确定@{}*{3}这一行是什么{\linewidth}{@{}*{3}{>{\arraybackslash}X}}意思。

这是我的 MWE:

    \documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\usepackage{booktabs,caption, makecell}
\usepackage{pdflscape,afterpage}

\begin{document}

\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Cognitive walkthrough goals, tasks and actions}
\centering
  \small
\begin{tabularx}{\linewidth}{@{}*{3}{>{\arraybackslash}X}}
\toprule\midrule[0.5pt]
 \thead{\textbf{Goal}}& \thead{\textbf{Task}} & \thead{\textbf{Action}} \\
\midrule
Evaluate the ease in which users can join projects & Access and account set up & 
\begin{enumerate} 
    \item Teast A: Video provides a powerful way to help you prove your point. \par
    Test B: Video provides a powerful way to help you prove your point. 
    \item Video provides a powerful way to help you prove your point.
\end{enumerate} \\
\addlinespace
Evaluate the ease in learning to map & Learning how to map & Read tutorial \\
\addlinespace
Contribute data & Contributing data by classifying maps & 
\begin{enumerate}
    \item Video provides a powerful way to help you prove your point.
    \item Test A: Video provides a powerful way to help you prove your point. \par
     Test B: Video provides a powerful way to help you prove your point.
     \item Video provides a powerful way to help you prove your point.
 \end{enumerate} \\
\addlinespace
Evaluate if the user likes using the application and whether they like using it & - & - \\
\bottomrule
 \end{tabularx}%
    \hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}

\end{document}

我还附加了一张我想要居中的图片作为示例。

在此处输入图片描述

提前致谢!

答案1

像这样?

在此处输入图片描述

  • 为了使单元格内容居中,同时保留X列的特征,您可以定义新的列类型,例如

    \newcolumntype{C}{>{\centering\arraybackslash}X}

  • 或者如果文档中只有一列,你可以按照下面的 mwe 中的方式编写

  • 除了在 mwe 中居中之外,下面enumerate列表的外观也得到了改进。为此添加了包enumerateetoolbox

\documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\usepackage{booktabs, makecell}
\usepackage{pdflscape}
\usepackage{caption}
\usepackage{enumitem}   % <--- added
\usepackage{etoolbox}   % <--- added
\AtBeginEnvironment{table}{%
    \setlist[enumerate]{nosep,     % <--- added
                        topsep     = 0pt,
                        partopsep  = 0pt,
                        leftmargin = *         ,
                        before     = \vspace{-0.6\baselineskip},
                        after      = \vspace{-\baselineskip}
                        }}

\begin{document}
    \begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Cognitive walkthrough goals, tasks and actions}
\label{table:comparison of techniques}
  \small
\begin{tabularx}{\linewidth}{@{}
                            X
>{\centering\arraybackslash}X  % content of `X` column is now centered
                            X
                            @{}}
    \toprule
\thead{\textbf{Goal}}& \thead{\textbf{Task}} & \thead{\textbf{Action}} \\
    \midrule
Evaluate the ease in which users can join projects
    &   Access and account set up
        &   \begin{enumerate}
            \item   Teast A: Video provides a powerful way to help you prove your point.

                    Test B: Video provides a powerful way to help you prove your point.
            \item Video provides a powerful way to help you prove your point.
            \end{enumerate}     \\
    \addlinespace
Evaluate the ease in learning to map
    &   Learning how to map
        &   Read tutorial   \\
    \addlinespace
Contribute data
    &   Contributing data by classifying maps
        &   \begin{enumerate}
            \item Video provides a powerful way to help you prove your point.
            \item Test A: Video provides a powerful way to help you prove your point.

                Test B: Video provides a powerful way to help you prove your point.
            \item Video provides a powerful way to help you prove your point.
            \end{enumerate}     \\
    \addlinespace
Evaluate if the user likes using the application and whether they like using it
    & -- & --                   \\
    \bottomrule
\end{tabularx}%
\end{table}
    \end{landscape}

相关内容