[Tex/LaTex] Different Caption-Setup for top and bottom figures

captionsfloats

is there a way to control the caption format used for figures, depending on where the figure has been placed? In particular, i would like to have different formatting of figure captions for figures that are placed to the top, and figures that are placed on the bottom of a page.

In my MWE i define a format that uses a horizontal line under the caption text. This is ok if the figure is on the top of the page and the caption is below the figure. But when the figure is at the bottom, i would put the caption above the figure – and then i'd like to use a caption format that has the horizontal line above the text.

Do you think something like that is possible, even automatically?

Cheers
Janos

P.s. in order to compile my MWE, you'd need an image called "blackbox".

\documentclass{article}
\usepackage[pdftex]{graphicx}
\usepackage{caption}
\usepackage{lipsum}
\DeclareCaptionFormat{figureFormat}{#1#2#3\hrulefill}
\captionsetup[figure]{format=figureFormat}
\begin{document}
    \begin{figure}[!t]
        \centering
        \label{fig:1}
        \includegraphics[width=\columnwidth]{blackbox}
        \caption{This figure is on the top. The caption should be on the bottom,
        and the horizontal line under it.}
    \end{figure}
    \lipsum[1]
    \lipsum[1]
    \begin{figure}[!b]
        \centering
        \caption{This figure is on the bottom, so it caption is above it. Now
        the horizontal line should be also above this text...}
        \label{fig:2}
        \includegraphics[width=\columnwidth]{blackbox}
    \end{figure}
\end{document}

Best Answer

As mentioned in the comments, I don't think there's a way to change the caption position automatically. However, LaTeX provides two commands that can place the rule automatically for you: \topfigrule and \botfigrule. Here's an example, but as with Steven's solution, this still requires you to specify what placement the figure will be to get the caption correct. (Also, remember to makes sure your labels follow the caption command or are inside it.)

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{lipsum}
\newcommand{\topfigrule}{\vspace{5pt} \hrule \vspace{-5pt}}
\newcommand{\botfigrule}{\vspace{-5pt} \hrule \vspace{5pt}}
\begin{document}
\lipsum[1]
    \begin{figure}[t]
        \centering
        \includegraphics[width=\columnwidth]{blackbox}
        \caption{This figure is on the top. The caption should be on the bottom,
        and the horizontal line under it.}
        \label{fig:1}
    \end{figure}
\lipsum[1]
\begin{figure}[b]
    \centering
    \caption{This figure is on the bottom, so it caption is above it. Now
    the horizontal line should be also above this text...}
    \label{fig:2}
    \includegraphics[width=\columnwidth]{blackbox}
\end{figure}
\lipsum[1]
\end{document}
Related Question