Wie zentriere ich eine Tabularx-Tabelle?

Wie zentriere ich eine Tabularx-Tabelle?

Ich möchte eine mit tabularx erstellte Tabelle horizontal zentrieren. Allerdings hat die tabularx-Tabelle einen Versatz nach rechts, den ich nicht entfernen kann:

\begin{table}
\small
\centering
\noindent
\begin{tabularx}{}{@{}X|X|X@{}}\hline
a & b & c \\ \hline
d & e & f
\\\hline
\end{tabularx}
\caption{This table is generated with tabularx. This table is generated with tabularx. This table is generated with tabularx. This table is generated with tabularx. This table is generated with tabularx. This table is generated with tabularx. }
\end{table}

\begin{table}
\small
\centering
\noindent
\begin{tabular}{ccc}\hline
a & b & c \\ \hline
d & e & f
\\\hline
\end{tabular}
\caption{This table is generated with tabular. This table is generated with tabular. This table is generated with tabular. This table is generated with tabular. This table is generated with tabular. This table is generated with tabular.}
\end{table}

Die Ausgabe sieht folgendermaßen aus: Screenshot von gerenderten Tabellen mit einem Vergleich von Tabularx und Tabular.

Wie kann ich die Tabelle in Tabularx horizontal zentrieren?

Antwort1

tabularxerfordert, dass Sie die Breite der resultierenden Tabelle angeben, damit die Breite der XSpalten berechnet werden kann. Verwenden Sie es also folgendermaßen:

Bildbeschreibung hier eingeben

\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{table}[t]
  \small
  \centering
  \begin{tabularx}{10em}{ @{} X | X | X @{} }
    \hline
    a & b & c \\
    \hline
    d & e & f \\
    \hline
  \end{tabularx}
  \caption{This table is generated with \texttt{tabularx}.}
\end{table}

\begin{table}[t]
  \small
  \centering
  \begin{tabular}{ *{3}{c} }
    \hline
    a & b & c \\
    \hline
    d & e & f \\
    \hline
  \end{tabular}
  \caption{This table is generated with \texttt{tabular}.}
\end{table}

Some regular text.

\end{document}

verwandte Informationen