4

I am badly looking for a way to give all my tables the same title in the document, that is used in the list of tables via caption[title]{long description...}. The reason is that my tables originate from R (xtable), which uses the exact above format every single time I recompute them, and I cannot change that. So unfortunately I could not make use of any different solutions. This is a very important matter to me because I have a lot of tables in my document.

Here is a MWE. As you can see the titles are missing, and only the labels are visible. The indentation in the longer description is on purpose.

Edit:

I made a picture to better illustrate this: enter image description here

  \documentclass[a4paper, 12pt, headsepline, smallheadings]{scrreprt}
\usepackage[labelfont={small,bf}, textfont=small,   labelsep=colon,singlelinecheck=false,format=plain, parindent=1em]{caption}
\newlength\myindention
\DeclareCaptionFormat{myformat}%
{#1#2\\\hspace*{\myindention}#3}
\setlength\myindention{1em}
\captionsetup{format=myformat}

\usepackage{chngcntr}
\counterwithout{table}{chapter} 

\begin{document}

\listoftables

\chapter{Introduction}
\begin{table}[h]
\caption[title table 1]{description table 1}
\fbox{content}
\end{table}

\begin{table}[h]
\caption[title table 2]{description table 2}
\fbox{content}
\end{table}

\end{document}

Thanks for any help. Best regards, Tom.

TomM
  • 1,694
  • 1
  • 19
  • 31
  • 1
    If I’m understanding you correctly, you want to use the optional – square bracketed – parameter from \caption inside \DeclareCaptionFormat, but that only supports the mandatory – curly braced – parameter as #3, whereas #1#2 are automatically generated label (“Table 1”) and separator (“:”). I’d say you use the standard format #1#2#3 and move the line break into each and every caption: \caption[title]{title\\\hspace*{\myindention} description}, probably add a macro for that. – Crissov Dec 22 '13 at 01:37
  • @Crissov yeah that's what I tought as well but I don't know how to achieve it – TomM Dec 22 '13 at 12:26

1 Answers1

7

If you are sure that all your captions have this format, adding the following lines in the preamble:

\let\oldcaption\caption
\renewcommand*\caption[2][]{%
\oldcaption[#1]{#1\\\hspace*{\myindention}#2}%
}

and removing the following

\DeclareCaptionFormat{myformat}%
{#1#2\\\hspace*{\myindention}#3}

\captionsetup{format=myformat}

you should achieve what you want.

MWE

\documentclass[a4paper, 12pt, headsepline, smallheadings]{scrreprt}
\usepackage[labelfont={small,bf}, textfont=small,   labelsep=colon,singlelinecheck=false,format=plain, parindent=1em]{caption}
\newlength\myindention
\setlength\myindention{1em}

\usepackage{chngcntr}
\counterwithout{table}{chapter}

\let\oldcaption\caption
\renewcommand*\caption[2][]{%
\oldcaption[#1]{#1\\\hspace*{\myindention}#2}%
}

\begin{document}

\listoftables

\chapter{Introduction}
\begin{table}[h]
\caption[title table 1]{description table 1}
\fbox{content}
\end{table}

\begin{table}[h]
\caption[title table 2]{description table 2}
\fbox{content}
\end{table}

\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410
  • Thanks a lot for your entry but it doesn't achieve yet what I needed. I think I have expressed my target format not carefully enough (see edits in original post, too). In your entry, the list of tables look correct. But in the document, the titles should be next to the table labels, such as Table 1 : title table 1, followed by the longer descriptions. In short: In the document I neede both, with the title ideally taken from the list of tables. – TomM Dec 22 '13 at 12:31
  • 1
    @TomM Sorry for misunderstanding. I've updated the answer, now it should be what you want. – karlkoeller Dec 22 '13 at 12:40
  • No reason to be sorry. Thanks a lot, this saved me so much handwork! :) – TomM Dec 22 '13 at 12:48