Is there any automatic way to use the first sentence of a caption as the short caption to be displayed in table of contents?
Precisely I want to write:
\caption{First Sentence. Second Sentence.} to be compiled as: \caption[First Sentence]{First Sentence. Second Sentence.}
After the first sentence I don't have necessary just one sentence.
Asked
Active
Viewed 2,018 times
11
2 Answers
8
As a quick-and-dirty hack, try this in your pre-amble:
\let\oldcaption\caption
\def\splitter #1. #2@@{\oldcaption[#1]{#1. #2}}
\def\caption#1{\splitter #1@@}
but beware that I'm assuming you have a very simple environment.
Thruston
- 42,268
-
Thanks; it works by adding just before \begin{document}, after adding babel package. I think your code is also a quick answer to this question: http://tex.stackexchange.com/questions/65680/automatically-bold-first-sentence-of-a-floats-caption?rq=1 by changing your second line with: \def\splitter #1. #2@@{\oldcaption[#1]{\textbf{#1}. #2}} – Mehran Ebrahimian May 09 '15 at 12:11
-
Does not work with subcaption:
! Package caption Error: The 'subcaption' package does not work correctly in compatibility mode.Is there a more reliable option? – user877329 Jul 01 '15 at 11:10 -
-
1This is great thank you. For anyone who wants to use this in a document that has some one sentence captions already be sure to add a space after the full-stop in order for the code to function correctly across the document. – Docconcoct Dec 07 '15 at 03:26
1
If you wrote all your labels directly after caption as I do:
sed 's/\(\\caption\){\(\\label{[^}]\+}\)\([^.]*\)\.\(.\+\)/\1[\3]{\2\3. \4/' report.tex
This works in some cases. It uses the GNU sed extension \+ otherwise it matches to much.
user877329
- 583
\Caption{First sentence}{Second sentence}? – Fran May 09 '15 at 11:33captions? – Thruston May 09 '15 at 11:48