[Tex/LaTex] How to align table and caption when table is centered on page

captionshorizontal alignmenttables

I haven't been able to figure out the best way to set up my tables. These are the features that they are supposed to have:

  1. Should be centered on page
  2. Caption should be "justified" and aligned with left border of the table. If caption spans over two line, then line should break at right border of the table.
  3. Additional comments should stand between caption and top border of table, and should as well be "justified" and aligned with left border of the table. If the additional comments contain a second line, it should break at the right border of the table.

To clarify I included two examples in the following code. The first is exactly what my tables are supposed to look like. It works only, because the table is so wide, that there are no other possibilities for alignments and line breaks. The second table just does not follow rule #2 and #3 as stated above. Does anyone have an idea how to solve these two problems?

Thanks a lot.

\documentclass[captions=tableheading]{scrbook}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[figuresright]{rotating} 
\usepackage[format=hang,justification=justified,singlelinecheck=false]{caption}[2004/07/16]
\usepackage{blindtext}
\usepackage{pdflscape}
\newcommand{\commenttable}[1]{\par{\itshape #1\par}\vskip 2mm}

\begin{document}

\begin{landscape}
\begin{table}
\caption{A table caption with a really fancy and ridiculously long description of what could and also should be said in just a few words}
\commenttable{Hello. \blindtext.}
\centering
\begin{tabular}{SSSSSSSSSSSSS}
\toprule
{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}\\
\midrule
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34&12.34&12.34  \\
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34&12.34&12.34  \\
\bottomrule
\end{tabular}
\end{table}
\end{landscape}

\begin{landscape}
\begin{table}
\caption{A table caption with a really fancy and ridiculously long description of what could and also should be said in just a few words}
\commenttable{Hello. \blindtext.}
\centering
\begin{tabular}{SSSSSSSSSS}
\toprule
{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}\\
\midrule
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  \\
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  \\
\bottomrule
\end{tabular}
\end{table}
\end{landscape}

\end{document}

Best Answer

Here is a solution that uses the caption and the floatrow packages. Your commenttable command has to be put in the first argument of the ttabbox command, just after caption{…}. To have a correct vertical spacing, I had to modify it slighly.

\documentclass[captions=tableheading]{scrbook}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[figuresright]{rotating}
\usepackage[format=hang,justification=justified,singlelinecheck=false]{caption}[2004/07/16]
\usepackage{blindtext}
\usepackage{pdflscape}
\newcommand{\commenttable}[1]{\vskip2ex\par{\itshape #1}}%\par\vskip 2mm

        \usepackage[tracking]{microtype}
        \usepackage{floatrow}  

       \DeclareCaptionFormat{leftmargin}{\captionsetup{textfont={small, md, up}, labelfont={small, sf, md, up}, labelsep=space, position = above, slc = off}\textls*[150]{\MakeUppercase{#1 #2}}#3}%
       \captionsetup{format = leftmargin}
\begin{document}

\begin{landscape}
\centering
\begin{table}
\centering
\ttabbox[\FBwidth]{\caption{A table caption with a really fancy and ridiculously long description of what could and also should be said in just a few words\commenttable{Hello. \blindtext.}}}
{%
  \begin{tabular}{SSSSSSSSSSSSS}
\toprule
{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}\\
\midrule
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34&12.34&12.34  \\
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34&12.34&12.34  \\
\bottomrule
\end{tabular}}%
\end{table}
\end{landscape}

\begin{landscape}
\centering
\begin{table}
\ttabbox{\caption{A table caption with a really fancy and ridiculously long description of what could and also should be said in just a few words\commenttable{Hello. \blindtext.}}}%
{%
\begin{tabular}{SSSSSSSSSS}
\toprule
{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}&{column}\\
\midrule
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  \\
12.34   &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  &12.34  \\
\bottomrule
\end{tabular}}%
\end{table}
\end{landscape}

\end{document} 

enter image description here enter image description here