As the warning message now reports, caption
does not know about what beamer
is doing, and as a result, gives up.
But beamer
already has hooks to the caption label/text fonts that we can use directly to achieve the same result:
\setbeamerfont{caption}{size=\scriptsize,shape=\itshape}
\setbeamerfont{caption name}{size=\scriptsize,shape=\scshape,series=\bfseries}
I put the changes inside \AtBeginEnvironment{table}{<...>}
from etoolbox
to keep the changes local to tables only; the captions for figures are unaffected, as illustrated below.
Of course, we need a font that has all the required combinations; I chose libertine
as suggested in the comments, but you may have a better idea of what you want to use.
\documentclass{beamer}
\mode<presentation> {
\usetheme{CambridgeUS}
}
\usepackage{libertine} % so that we have all the required fonts
\usepackage{etoolbox} % for patching the table environment
\AtBeginEnvironment{table}{% change the caption fonts only inside table (figure unaffected)
\setbeamerfont{caption}{size=\scriptsize,shape=\itshape}
\setbeamerfont{caption name}{size=\scriptsize,shape=\scshape,series=\bfseries}
}
\begin{document}
\begin{frame}[t]
\frametitle{Tables Testing}
\begin{table}[htbp]
\centering
\caption{default}
\begin{tabular}{|cc|}
\hline
column A & column B \\ \hline
line1 & line2 \\ \hline
\end{tabular}
\label{default}
\end{table}%
\begin{figure}
\centering
Test figure.
\caption{Test figure caption.}
\end{figure}
\end{frame}
\end{document}
When you mention "hyperlink to the figure", I assume you're referring to the hyperlink from the LoF. Yes, that's all based on the \caption
, which is set correctly. However, as is clear from your example code, inserting a newline in LyX actually creates a separate group around the caption:
\begin{figure}[h]
\noindent \begin{centering}
\includegraphics[<opts>]{<filename>}\caption{<caption>}
\par\end{centering}
\noindent \centering{}\label{<label>}
\end{figure}
From the above we can see that \caption
is placed inside a centering
group. Now, according to Understanding how references and labels work you'll see that \label
uses \@currentlabel
- a macro that is updated when you step a counter. In this case the counter is stepped as part of the call to \caption
. However, this update is reverted when the group is closed, because the update is only local to the group that its used in.
So it seems you should NOT put an empty line between the \caption
and \label
in LyX. It's just the way LyX interprets new lines within structures that seems strange. Of course, as a GUI-like editor for LaTeX, it attempts to remove some of the code-like insertions from the user. However, with this intuitiveness comes some assumptions... something that is clearly incorrectly interpreted in this case.
Best Answer
Actually,
\label
must appear after (not necessarily inside)\caption
, because the\caption
command increments the counter to which\label
's argument associates itself.