0

This code:

\documentclass[a4paper,11pt]{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\begin{table}
  \centering
  \footnotesize
  \begin{tabularx}{\textwidth}{l X X}
    \toprule
    Table title \\
    \midrule
    Some short text \\
    \addlinespace
    Some fairly short text \\
    \addlinespace
    Some shorter text \\
    \addlinespace
    Some short text \\
    \addlinespace
    Some fairly short text \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

Makes this table:

enter image description here

But how can I centre the tables and get the lines to be the same width as the text in the table?

1
  • 3
    You are defining a table with the width of the width of text, hence the lines are drawn that long. You are defining 3 colums, but are using only one. Try \begin{tabular}{c} instead.
    – Johannes_B
    Aug 8, 2015 at 8:20

1 Answer 1

1
  • You have defined three columns but just use one
  • A centred column is defined by the specifier c
  • If you use tabularx with \textwidth, it is not surprising that your lines are that long
  • Do not use \addlinespace that often. Just if it is needed in order to clearly separate some parts of the table.

% arara: pdflatex

\documentclass[a4paper,11pt]{article}
\usepackage{booktabs}

\begin{document}    
\begin{table}
    \centering
    \footnotesize
    \begin{tabular}{c}
        \toprule
        Table title \\
        \midrule
        Some short text \\
        Some fairly short text \\
        Some shorter text \\
        Some short text \\
        Some fairly short text \\
        \bottomrule
    \end{tabular}
\end{table} 
\end{document}

enter image description here

You must log in to answer this question.

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