2

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}
1
  • Welcome to TeX.SX!
    – Adam Liter
    Apr 15 '14 at 16:48
1

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

0
1

This is tailor made for the boxhandler package, which sets captions in the style you asked, almost by default. The captioning is configurable. However, one must enter the table as a macro \bxtable{caption}{content}, not an environment, which some people will find bothersome.

The only challenge was to align the comment with the table automagically. To do that, I set the tabular in a temporary box, and made the comment in a \parbox of that width, and stacked it above the tabular box.

Also, because the image is rotated, the maximum allowable caption width has to be reset (I initially thought this a package bug until I realized what was going on).

\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}
\usepackage{boxhandler}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{landscape}
% Need to reset max caption width, because of rotated image
\constrainCaptionWidth[1in]{\linewidth}
% Make caption flush with outer edge of table content
\setlength{\TableDeadMargin}{0em}
\bxtable{%
A table caption with a really fancy and ridiculously long description of 
what could and also should be said in just a few words}{%
\setbox0=\hbox{%
\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}}%
\setstackgap{S}{12pt}%
\Shortstack{\parbox{\wd0}{\itshape Hello \blindtext}\\ \box0}
}
\end{landscape}
\end{document}

enter image description here

1
  • That does exactly what I need. Great work! Apr 16 '14 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.