Graphics, Figures & TablesHide caption sep if no caption text

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

Hide caption sep if no caption text

Post by NinV »

Hi,

I would like to modify the \caption command so that it shows the separator only there is some text in the caption.

With a text

Code: Select all

Fig. 1: Any text
without any text

Code: Select all

Fig. 2
Where can I get the source code of this command or, better, of all latex commands?

Thank you very much,
Nino

PS Even a solution to my problem will be highly appreciated :D
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Hide caption sep if no caption text

Post by sommerfee »

Loading the caption package should be sufficient. It will hide the caption separator automatically if there is no caption text.

Code: Select all

\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{figure}
% ...
\caption{Any text}
\end{figure}
\begin{figure}
% ...
\caption{}
\end{figure}
\end{document}
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

Re: Hide caption sep if no caption text

Post by NinV »

Sorry, sommerfee. I didn't say that I wouldn't like to use the caption package. I would like to use only the KOMA-scripts (scrbook).

I know that in these scripts there are commands to customize captions, but I didn't succeed to get what I want :(

Thanks for help.
Nino
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

Hide caption sep if no caption text

Post by NinV »

Hi!

I'm back again, sorry for bothering you :oops:

To solve my problem, I've tried to redifine \@makecaption:

Code: Select all

\makeatletter

\renewcommand\@makecaption[2]{%
   \vskip\abovecaptionskip
   \sbox\@tempboxa{#1: #2}%
   \ifx\@empty#2                    % THAT DOESN'T WORK
     #1\par
   \else
    \ifdim \wd\@tempboxa >\hsize
      \noindent #1: #2\par
    \else
      \centering
      \makebox[\linewidth][c]{ #1: #2}\par
    \fi
   \fi
   \vskip\belowcaptionskip   
}

\makeatother
But the folliwing line doesn't work at all!

Code: Select all

\ifx\@empty#2                    % THAT DOESN'T WORK
I've tried "ifthenelse" and changing the condition to check, but no one worked!

Can you help me to understand where I am making mistakes?

Thanks a lot.

PS The minimal working example is attached
Attachments
prova4.tex
(1.58 KiB) Downloaded 264 times
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

Re: Hide caption sep if no caption text

Post by NinV »

Please help me :cry:
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Post Reply