[Tex/LaTex] Align table caption with left-hand edge of tabular material

captionshorizontal alignmenttablesthreeparttable

Below is the code I use.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{subfigure} 
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space,justification=raggedright,singlelinecheck=off}
\captionsetup[figure]{labelsep=quad}
\usepackage{threeparttable}

\begin{document}

\begin{table}[ht]
\centering
\caption{Data Partitioning} \label{exp_dataset}
\begin{tabular}{c|c|c}
\hline
\#Set & Training Data (7d) & Testing Data (1d) \\ \hline
1 & 07/06/2015-07/12/2015 & 07/13/2015 \\ \hline
2 & 07/09/2015-07/15/2015 & 07/16/2015 \\ \hline
3 & 07/12/2015-07/18/2015 & 07/19/2015 \\ \hline
\end{tabular} 
\end{table}

\end{document}

But the output is like below:

enter image description here

What I want is like below: (The table should be at the center of the page. The caption should be left-align with the table.)

enter image description here

I tried the answers in related posts. None of them works out.

Best Answer

You need to encase the \caption statement and the tabular environment in a threeparttable environment.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space, 
         justification=raggedright, singlelinecheck=off}
\usepackage{threeparttable}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable} % <--- new
\caption{Data Partitioning} \label{exp_dataset}
\begin{tabular}{c|c|c}
\hline
\#Set & Training Data (7d) & Testing Data (1d) \\ \hline
1 & 07/06/2015-07/12/2015 & 07/13/2015 \\ \hline
2 & 07/09/2015-07/15/2015 & 07/16/2015 \\ \hline
3 & 07/12/2015-07/18/2015 & 07/19/2015 \\ \hline
\end{tabular} 
\end{threeparttable} % <--- new
\end{table}
\end{document}

enter image description here

Related Question