2

I have created a table using tabularx but I can't seem to centre the text within the columns. I have tried to use 'X' and 'c' (which works on tabular) but nothing seems to work. Can someone please advise? I am also unsure what @{}*{3} in the line {\linewidth}{@{}*{3}{>{\arraybackslash}X}} means.

Here's my 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}

I've also attached a picture of what I'd like to centre as an example.

enter image description here

Thanks in advance!

  • for centering in X column type: >{\centering\arraybackslash}X} – Zarko Apr 17 '18 at 12:45
  • Another related question - if I wanted to move the 'contributing data by classifying maps' further down (to the centre of the box), how could I do this? – Kevin Apr 17 '18 at 13:44
  • 1
    one problem to question, please :-). if you like to move only this text in whole column, than you can do this by use of multirow cell. if you like to vertical center text in all columns, than redefine X column as: \renewcommand\tabularxcolumn[1]{m{#1}}. your comment is not very clear ... – Zarko Apr 17 '18 at 13:55
1

like this?

enter image description here

  • for centering of cells' contents and at the same time preserve features of X columns, you can define new column type, for example

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

  • or in the case that in document is only one such column you can write as is done in mwe below

  • beside centering in mwe below is improved appearance of the enumerate list. for this is added the package enumerate and etoolbox

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.