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 a problem formatting my captions for figures/tables.

What should happen is the following: I need one line above the image and two lines above and below the caption. To make it look good, I have to adjust vertical spacing several times.

A problem now occurs depending on whether the caption is displayed in one or several lines. For single line captions I would need to adjust by the vspacing by {-0.8 \baselineskip}, in case of a multiline caption only by {-0.1 \baselineskip} for the line below the caption to have exactly the same space to the bottom of the text. I'm not so familiar with LaTeX or typesetting, so I don't understand why this happens at all. A solution would be to somehow figure out the number of lines in the caption, but I have no idea how to do this. I tried to "abuse" the lineno package for my needs, but without any success.

Has anyone an idea how to solve this or what causes the problem at all?

Below the code for my image insertion.

\newcommand{\includewrappedfigure}[6][0pt]{
% example params: [0pt]{R}{.3}{afigurefile}{figure with long caption}{fig:afigure}
    \begin{wrapfigure}{#2}{#3\textwidth}
    \centering
    \vskip -.8 \baselineskip
    \hrule
    \includegraphics[width=#3\textwidth, keepaspectratio]{#4}
    \vskip -1 \baselineskip
    \hrule
    \vskip -0.8 \baselineskip
    \caption{#5}
    \label{#6}
    \vskip -.1 \baselineskip % for MULTI line captions
    % \vskip -.8 \baselineskip % for SINGLE line captions
    \hrule
\end{wrapfigure}
}
share|improve this question
    
Hi Stefan, welcome! It is not customary to sign in the post here, I have removed that. Have a great stay! :) –  zeroth Mar 6 '12 at 17:03
    
@zeroth: I will remember that. Thanks. –  Stefan Mar 6 '12 at 21:28
add comment

1 Answer

up vote 7 down vote accepted

Unfortunately you didn't supply a minimal working example, so I don't know if you are using a class that uses the same caption code as article, however article uses:

\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1: #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

The #1: #2\par is the multi-line case, the \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% is the single line case, so you can redefine this command adding whatever spacing you need in each case.

share|improve this answer
    
Thanks, that gave me a great hint! I'm using KOMA-Script report-class and now found the \@@makecaption. It works essentially the same way (\ifdim-clause) and enables me to extend it with the necessary case-dependent line-drawing. –  Stefan Mar 6 '12 at 21:22
add comment

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.