Como centralizar a tabela tabularx?

Como centralizar a tabela tabularx?

Quero centralizar horizontalmente uma tabela gerada com tabularx. Mas a tabela tabularx tem um deslocamento para a direita que não consigo remover:

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

A saída é semelhante a esta: Captura de tela de tabelas renderizadas comparando tabularx e tabular.

Como posso centralizar horizontalmente a tabela no tabularx?

Responder1

tabularxrequer que você especifique uma largura da tabela resultante para que ela possa calcular as larguras das Xcolunas. Então, use assim:

insira a descrição da imagem aqui

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

informação relacionada