[Tex/LaTex] Multiline Caption

captions

I want a caption of two lines, with the second line not centered but aligned to the left.

enter image description here

This is the result of the following code, \captionsetup{justification=raggedright} doesn't seem to work. What am I doing wrong?

\documentclass[a4paper,twoside,12pt]{scrreprt}
\usepackage{fontspec}
\usepackage{caption}
\usepackage{booktabs}
\begin{document}
\begin{table}
  \centering
  \captionsetup{justification=raggedright}
\begin{tabular}{cc}
  \toprule
  A & B 
\\ \midrule
  11111111111111111  & 1111111111111111\\
  22222222222222222  & 2222222222222222\\
  33333333333333333  & 3333333333333333\\
  44444444444444444  & 4444444444444444\\
  55555555555555555  & 5555555555555555\\
  66666666666666666  & 6666666666666666\\
\bottomrule
\end{tabular}
\caption{Caption caption caption caption\\
caption caption}
\end{table}
\end{document}

Best Answer

If you use a threeparttable environment, it computes the width of your table, and it works either with the plain or the hang formats:

 \documentclass[a4paper,twoside,12pt]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{threeparttablex}

\begin{document}

\begin{table}[!h]
\captionsetup{format =plain}%
\centering
\begin{threeparttable}
\begin{tabular}{cc}
\toprule
A & B
\\ \midrule
11111111111111111 & 1111111111111111\\
22222222222222222 & 2222222222222222\\
33333333333333333 & 3333333333333333\\
44444444444444444 & 4444444444444444\\
55555555555555555 & 5555555555555555\\
66666666666666666 & 6666666666666666\\
\bottomrule
\end{tabular}
\caption{Caption caption caption caption\\
caption caption. }
\end{threeparttable}
\end{table}

\begin{table}[!h]
\captionsetup{format =hang}%
\centering
\begin{threeparttable}
\begin{tabular}{cc}
\toprule
A & B
\\ \midrule
11111111111111111 & 1111111111111111\\
22222222222222222 & 2222222222222222\\
33333333333333333 & 3333333333333333\\
44444444444444444 & 4444444444444444\\
55555555555555555 & 5555555555555555\\
66666666666666666 & 6666666666666666\\
\bottomrule
\end{tabular}
\caption{Caption caption caption caption\\
caption caption. }
\end{threeparttable}
\end{table}\end{document} 

Note that it doesn't seem to work with the ThreePartTableenvironment (from threeparttablex), so that you can't break your tables through pages.

enter image description here

Related Question