1

I am trying to set up a tabularx table with very long item descriptions in first column

\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc} 
\usepackage{tabularx} 
\usepackage{booktabs}

\begin{document}
\begin{table}[!htb]
    \begin{tabularx}{\textwidth}{lccc}\toprule
    Item & MW & SD & span\\\midrule
    This is a very very  very very  very very  very very  very very  very very  very very  very very  long item description. & $2.58$ & $0.90$ & $1-4$  \\\bottomrule
    \end{tabularx}
\end{table}
\end{document}

At the moment, it compiles badly because LaTeX allows first column to extend to a lenght of the whole item description. What can I do to get a better result in which I have e.g. 5 lines text, but an acceptable broadness of the column?

  • 1
    It should compile very badly, i.e. not at all, because \toprule is unknown. Please add \usepackage{booktabs} to your MWE also – user31729 Jul 3 '14 at 9:30
  • 2
    Use columntype X for the first column: \begin{tabularx}{\textwidth}{Xccc} – esdd Jul 3 '14 at 9:33
  • Works perfectly fine. Additional question: how can I vertically center the values in my other colums (1-lined) if the item description goes along several lines? – Jens Jul 3 '14 at 9:46
2

Use columntype X for the first column:

\begin{tabularx}{\textwidth}{Xccc}

The X is a column of the type p. If you want to vertically center the values in the other columns you have to redefine the \tabularxcolumnn to

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

enter image description here

Code:

\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc} 
\usepackage{tabularx} 
\usepackage{booktabs}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}
\begin{table}[!htb]
    \begin{tabularx}{\textwidth}{Xccc}\toprule
    Item & MW & SD & span\\\midrule
    This is a very very  very very  very very  very very  very very  very very  very very  very very  long item description. & $2.58$ & $0.90$ & $1-4$  \\\bottomrule
    \end{tabularx}
\end{table}
\end{document}

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.