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 want to add a line beneath the figure caption such as

Figure 1


Figure caption text here....

Example figure

I managed to include a newline, change the color and look of the caption via caption package:

\usepackage[font=small,
            format=plain,
            labelformat=simple, 
            labelsep=newline,
            singlelinecheck=false,
            labelfont=bf,
            up
            ]{caption}
\captionsetup{labelfont={color=mybluecolor,bf}}

but cannot put a line (horizontal rule) as in the linked example. How can I do this?

share|improve this question
    
Welcome to TeX.sx! There is no link; you can add the image with the button, just remove the ! in front of the produced link. Another user with sufficient privileges will reinstate it. –  egreg Dec 13 '12 at 11:40
    
How long should the rule be? As long as the caption text, the actual figure, or even the width of the running text? –  lockstep Dec 13 '12 at 11:58
3  
I have added an example figure. The length of the line is equal to the width of the text in this case. –  Michael Foxchess Dec 13 '12 at 12:20

2 Answers 2

The caption package allows you to define your own caption format with \DeclareCaptionFormat.

\DeclareCaptionFormat{<name>}{<code using #1, #2 and #3>}

where #1 refers to the label, #2 to the label separator and #3 to the caption text. This is described in section 4 Own Enhancements of the caption manual. Here is an example using tabu to typeset the caption which should give you a general idea:

\documentclass{article}
\usepackage{caption,xcolor,tabu}
\colorlet{captionlabel}{blue!100!black!85}

\DeclareCaptionFormat{custom}{%
 \begin{tabu} to \linewidth {@{}X@{}}
   \strut #1 \\\hline
   \strut #3
 \end{tabu}
}
\captionsetup{
  font=small,
  format=custom,
  singlelinecheck=false,
  labelfont={bf,color=captionlabel}
}
\usepackage{lipsum}
\begin{document}

\lipsum[1]

\begin{figure}[ht]
 \centering
 \rule{5cm}{3cm}
 \caption{\protect\lipsum*[4]}
\end{figure}

\lipsum[2]

\end{document}

enter image description here

share|improve this answer
    
Thanks! It helped me. –  Michael Foxchess Dec 13 '12 at 12:40
    
@MichaelFoxchess In that case you should upvote and (unless better answers appear) accept cgnieder's answer. –  lockstep Dec 13 '12 at 12:48
1  
Out of curiosity: could the downvoter explain why? –  cgnieder Dec 13 '12 at 14:28
    
I am not the downvoter, but I think the first line is a little too close to the rule. –  math Mar 20 '13 at 16:17
    
@math that could easily be changed by using the optional argument of \\ . I don't think it would be worth a downvote... –  cgnieder Mar 20 '13 at 17:43

A way with minimal intervention: just declare a new separator.

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{xcolor}
\definecolor{mybluecolor}{rgb}{.204,.486,.741}
\usepackage{lipsum}

\usepackage{caption}

%%% Define a new caption separator
\DeclareCaptionLabelSeparator*{newlinerule}{\par\kern2pt\hrule\kern1pt}

\captionsetup{
  font=small,
  format=plain,
  labelformat=simple,
  labelsep=newlinerule,
  singlelinecheck=false,
  labelfont={color=mybluecolor,bf},
}

\begin{document}

\lipsum[1]

\begin{figure}[!hp]
\centering
\includegraphics[width=.8\textwidth]{x}
\caption{\protect\lipsum*[2]}
\end{figure}

\lipsum[3]

\end{document}

enter image description here

share|improve this answer
    
The values 2pt, 1pt are a rule of thumb or there's a good typographical reason for them? –  tohecz Dec 13 '12 at 13:44
    
@tohecz Just a quick setting, without looking too much into the details; if in the language used the word for "figure" has no descenders, they probably need to be changed. In any case they can be globally modified by acting in just one place. –  egreg Dec 13 '12 at 13:48

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.