[Tex/LaTex] Table caption position

captionstables

I would like to have my caption at the top right of the table.
I've already set it at the top right of the paper using:

\floatstyle{plaintop}
\restylefloat{table}
\captionsetup[table]{justification=raggedleft,singlelinecheck=off}

But I need to have it on the top right of the table, as on picture.
wrong caption position

The column width is set with \renewcommand{\tabcolsep}{0.3em}

Best Answer

I suggest you load the threeparttable package and embed the \caption directive and the tabular (or array) environment inside a threeparttable environment.

enter image description here

\documentclass{article}
\usepackage{caption,threeparttable}
\captionsetup{justification   = raggedleft,
              singlelinecheck = off}
\begin{document}
\begin{table}
\centering
\begin{threeparttable}
\caption{A caption}
\begin{tabular}{|cccccccc|}
\hline
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh \\
\hline
\end{tabular}
% optional: provide 'tablenotes' environment if needed
\end{threeparttable}
\end{table}
\end{document}