# Center table and align caption over table

I have a small table that I want to center in a document. I can do this but the caption then is left justified rather than aligning with the centered table. I'd like to center the table and make the caption align with the centered table. How can I achieve this?

Minimal example (I left in any package information in case this is useful):

\documentclass{scrartcl}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage{scrextend}
\usepackage[style=apa, backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\usepackage{amsmath}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
{hyperref}
\hypersetup{pdfstartview={XYZ null null 1}}
\usepackage{enumerate}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[justification=justified,singlelinecheck=false]{caption}
\usepackage{hyperref}
\usepackage{here}

\newenvironment{my_enumerate}{
\begin{enumerate}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}}{\end{enumerate}
}

\begin{document}
\begin{table}[ht]
\centering
\caption{Descriptive Statistics. \label{desc}}
\begin{tabular}{lccccc}
\toprule
&  & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach  & n & mean & sd & mean & sd \\
\midrule
1  & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2  & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3  & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All  & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

-

You can also try the package TABLE from River Valley. The package provides the following:

• include a landscape table as a float.
• format the caption exactly to the width of the table.
• some other hooks that would add a little extra vertical space around horizontal rules in the tabular.
\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage{txfonts,array}

\usepackage[debug]{Table}

\begin{document}

\TABLE{\label{desc} Descriptive Statistics over a Mean Approach to sd and a, descriping both post and pre}
{\begin{tabular}{lccccc}
\toprule
&  & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach  & n & mean & sd & mean & sd \\
\midrule
1  & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2  & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3  & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\\midrule
All  & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
}
\end{document}


And it seems to automatically centre the table on the page.

-

When using the caption package anyway one could use the command \captionbox offered by that package (at least since version 3.2):

\documentclass[captions=tableheading]{scrartcl}
\usepackage[american]{babel}
\usepackage{enumerate}
\usepackage{booktabs}
\usepackage[justification=justified,singlelinecheck=false]{caption}

\begin{document}
\begin{table}[ht]
\centering
\captionbox{Descriptive Statistics. \label{desc}}{%
\begin{tabular}{lccccc}
\toprule
&  & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach  & n & mean & sd & mean & sd \\
\midrule
1  & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2  & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3  & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All  & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}}
\end{table}
\end{document}

-

If your aim is to typeset the caption justified and to adjust it to the width of the tabular content, you could load the floatrow package (which does away with the need to add \centering) and put the tabular environment plus the caption inside a \ttabbox.

\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage[justification=justified,singlelinecheck=false]{caption}
\usepackage{floatrow}

\begin{document}

\begin{table}[ht]
\ttabbox{%
\caption{Descriptive Statistics. \label{desc}}%
}{%
\begin{tabular}{lccccc}
\toprule
&  & \multicolumn{2}{c}{pre} & \multicolumn{2}{c}{post} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
approach  & n & mean & sd & mean & sd \\
\midrule
1  & $12$ & $24.2$ & $\phantom{0}8.3$ & $54.3$ & $11.0$ \\
2  & $12$ & $25.5$ & $\phantom{0}9.4$ & $65.2$ & $16.3$ \\
3  & $12$ & $26.3$ & $\phantom{0}9.1$ & $63.2$ & $12.5$ \\
All  & $36$ & $25.3$ & $\phantom{0}8.8$ & $60.9$ & $13.9$ \\
\bottomrule
\end{tabular}
}
\end{table}

\end{document}

-