[Tex/LaTex] Center table and align caption over table

captionsfloatshorizontal alignment

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,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {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} 

Best Answer

NB! The link to the TABLE-package at River Valey website is dead. I have not fond the TABLE-package other places. It is not on CTAN.

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.

enter image description here