CとAの数物 Note

数学と物理のはざまに棲息。

latex : table の caption ごと左寄せする方法

latex で文章を書いているとき、表を(cell ごとのでなく、全体を)左寄せに書きたいときがある。しかし

\documentclass{article}

\begin{document}
Hogehogehogehoge

\begin{table}[h]
\caption{Hoge}
\begin{tabular}{|c|c|c|c|}
\hline
A & B & C & D  \\
\hline
E & F & G & H \\ 
\hline
\end{tabular}
\end{table}

Hogehoge
\end{document}

このようにやると、出力が下のようになり、caption が取り残される。table 環境を flushleft 環境で囲っても同じ結果になる。
f:id:C-and-A:20200704144751p:plain:w500


これは threeparttable パッケージを使えば解決できた。下のように tabular 環境を threeparttable 環境で囲む。

\documentclass{article}

\usepackage{threeparttable}

\begin{document}
Hogehogehogehoge

\begin{table}[h]
\begin{threeparttable}
\caption{Hoge}
\begin{tabular}{|c|c|c|c|}
\hline
A & B & C & D  \\
\hline
E & F & G & H \\ 
\hline
\end{tabular}
\end{threeparttable}
\end{table}

Hogehoge
\end{document}

出力は下のようになり、caption も引っ張ってこれる。
f:id:C-and-A:20200704145912p:plain:w500


threeparttable にはほかにも機能がありそうなので、色々試してみたい。