Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have done some searching but not had much luck. I would like to be able to see and use the label of my caption as a 'title' for the caption text.

An example:

\documentclass[11pt]{article}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{relsize}
\usepackage{tabu}
\usepackage{booktabs}

\usepackage[
justification=justified,
labelfont=bf,
textfont=small,
textfont=it,
labelsep=newline]{caption}


\begin{document}

\listoftables

\begin{table}
\centering
\footnotesize

\sffamily{

\begin{tabu} to 
\textwidth {lrl}
\toprule
&    15,639 patients \\
\midrule
Age (yrs)&     70.0&(18.0--104.0)\\
Male sex&    8,113&(51.9)\\
CCMDS Level of Care&&\\
\hspace*{1em}\smaller[1]{High dependency}&    2,708&(17.3)\\
Nursing observations&&\\
\hspace*{1em}\smaller[1]{Continuous monitoring}&    4,497&(28.8)\\
\hspace*{1em}\smaller[1]{Up to 4 hrly (inclusive)}&    7,435&(47.5)\\
\hspace*{1em}\smaller[1]{Less frequently than 12 hrly}&    2,080&(13.3)\\
Delayed referral to critical care&    2,012&(12.9)\\
Reported sepsis diagnosis&&\\
\hspace*{1em}\smaller[1]{Likely}&    5,741&(36.7)\\
\hspace*{1em}\smaller[1]{Unlikely}&    4,232&(27.1)\\
\bottomrule
\end{tabu} 

} 

\caption[Baseline characteristics]{All study patients. Numbers are mean(SD), or median(IQR)}

\label{baseline_pt_chars} 
\normalfont
\end{table}
\end{document}


\usepackage[labelfont=bf]{caption}
\begin{table}
... table code here ....
\caption[Baseline characteristics]{All study patients. Numbers are mean(SD), or median(IQR)} 
\end{table}

And for this to be formatted as

Table 1: Baseline characteristics All study patients. Numbers are mean(SD), or median(IQR)

Is this possible? Or should I just manually code all the formatting outside of the caption but inside the float environment ... which would mean writing the label twice (once for the caption and the list of tables, and once inside the float environment)?

I hope the question is clear?

share|improve this question
    
Welcome to TeX.sx! No need to add thanks to your Q, simply upvote any good replies your receive. It is useful if you post a Minimal Working Example (MWE) showing your problem instead of just a code snippet. That way others can test your code more easily. –  Peter Jansson Feb 7 '13 at 22:55
    
I guess that you have to redefine the \caption command to use the optional argument together the mandatory argument. –  Sigur Feb 7 '13 at 23:02
    
@Peter Jannson> Added the code in more detail. –  drstevok Feb 7 '13 at 23:24
add comment

1 Answer

up vote 10 down vote accepted

My suggestion is to define a new command for the purpose:

\documentclass{article}
\usepackage[labelfont=bf]{caption}
\newcommand{\tablecaption}[2]{\caption[#1]{\textbf{#1} #2}}
\begin{document}
\listoftables

\section{Something}

\begin{table}[htp]
... table code here ....
\tablecaption{Baseline characteristics}{All study patients. Numbers are mean (SD), or median (IQR)}
\end{table}
\end{document}

Redefining \caption would mean having the same behavior also for figures.

enter image description here

It's possible to use the same syntax as \caption and the same command name; but since the optional argument becomes mandatory, I believe the solution with the new command is preferable. Anyhow, here it is:

\documentclass{article}
\usepackage[labelfont=bf]{caption}

\usepackage{letltxmacro}
\AtBeginDocument{% caption does its business here
  \LetLtxMacro{\captioncaption}{\caption}
  \renewcommand{\caption}[2][]{\captioncaption[#1]{\textbf{#1} #2}}
}

\begin{document}
\listoftables

\section{Something}

\begin{table}[htp]
... table code here ....
\caption[Baseline characteristics]{All study patients. Numbers are mean (SD), or median (IQR)}
\end{table}
\end{document}

If the "optional" argument may be missing from some captions, we have to do it in a slight different way:

\usepackage{letltxmacro}
\AtBeginDocument{% caption does its business here
  \LetLtxMacro{\captioncaption}{\caption}
  \renewcommand{\caption}[2][]{%
     \if\relax\detokenize{#1}\relax
       % Missing optional argument
       \captioncaption{#2}%
     \else
       % The optional argument is specified
       \captioncaption[#1]{\textbf{#1} #2}%
     \fi}
}
share|improve this answer
    
Is it possible to define the new command not with 2 arguments but with one optional and one mandatory so it would be not necessary to replace the brackets by braces? –  Sigur Feb 7 '13 at 23:09
    
@Sigur Yes; but if an argument is mandatory, it's semantically better to specify it in braces. –  egreg Feb 7 '13 at 23:10
    
OK, I agree. But I guess that the OP wants the optional argument to be used but not always. For example, if there is no optional caption, the result would be the same as the default one. –  Sigur Feb 7 '13 at 23:12
    
@egreg: great! thanks that works brilliantly ... and I'll live with the braces not brackets:) –  drstevok Feb 7 '13 at 23:25
1  
@TomM Weird; I'll investigate. –  egreg Dec 20 '13 at 16:14
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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