tabularx テーブルを中央に配置するにはどうすればいいですか?

tabularx テーブルを中央に配置するにはどうすればいいですか?

tabularx で生成されたテーブルを水平方向に中央揃えにしたいのですが、tabularx テーブルには右側へのオフセットがあり、それを削除することはできません。

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

出力は次のようになります。 tabularx と tabular を比較したレンダリングされたテーブルのスクリーンショット。

tabularx でテーブルを水平中央に配置するにはどうすればよいでしょうか?

答え1

tabularx列の幅を計算するために、結果のテーブルの幅を指定する必要がありますX。したがって、次のように使用します。

ここに画像の説明を入力してください

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

関連情報