For customizing captions, the caption
packages is highly recommendable. Besides a lot of other features, you can also adjust the width of captions, for example:
\captionsetup{width=6cm}
You may use this command globally in your preamble but also within a table environment, which keeps it local and thus limits the effect of this setting.
With a KOMA-Script class, without the caption
package, you could use \setcapwidth
:
\setcapwidth[c]{6cm}
Since you use a background image, you might know the necessary width. Even if you don't know it, the width for the caption could be automatically calculated from the width of the table or image. Then the command \settowidth
comes handy`.
create a macro for the width: \newlength{\cwidth}
get the width of the object: \settowidth{\cwidth}{object}
set the caption widht by one of the two commands at the beginning of this answer
print out the object
You could even write a macro for automatizing that, like
\newcommand{\autowidth}[1]{%
\settowidth{\cwidth}{#1}%
\captionsetup{width=\cwidth}%
#1%
}
This works well with images. Tables might be harder as object, but in your case you could refer to your background images.
This should work
\renewcommand{\tablename}{Figure.} % in preamble
EDIT: I realize that any tables that you have will also be labelled 'Figure'. Don't know how to work around that.
UPDATE: As Bernard suggested below, I learnt that you can use \captionof
on a case-by-case basis, which is really handy if you have both figures and tables in your document.
\documentclass[12pt]{report}
\usepackage{caption}
%\renewcommand{\tablename}{Figure.}
\begin{document}
\captionof{figure}{example}
\vspace{-10pt} %This brings the caption closer to the table
\begin{table}[htp]
\centering
\begin{tabular}{llll} \hline
a & b & c & d \\
a & b & c & d \\
\end{tabular}
\end{table}
\captionof{table}{example}
\begin{table}[htp]
\centering
\begin{tabular}{llll} \hline
a & b & c & d \\
a & b & c & d \\
\end{tabular}
\end{table}
\end{document}
Best Answer
You haven't provided your requirements for quite a few design aspects, so I have to make some assumptions. In particular, in the examples below I'll assume that the two side-by-side figures should jointly span the entire width of the text block.
You also haven't indicated whether or not the side-by-side figures should be able to float, in the LaTeX sense of the word. I'll provide suggestions for both cases:
If you want the two side-by-side figures to be able to float (while staying next to each other, of course), set up a
figure
environment that encases twominipage
environments. Eachminipage
could be as wide as0.48\textwidth
, say. Inside eachminipage
, use an\includegraphics
instruction (with the width of the graph set to1\linewidth
) to load the images of interest. As usual, use\caption
and\label
statements, but now within aminipage
, to create the captions and set up a means for cross-referencing thefigures
.If you do not want the side-by-side figures to float, change the preceding setup as follows:
Remove the
\begin{figure}
and\end{figure}
statements, but do keep theminipage
-related statements. If you want the two minipages to span the width of the text block, be sure to provide a\noindent
statement right before the first one.Replace the
\caption{...}
statements with\captionof{figure}{...}
statements. You need to load thecaption
package to get access to the\captionof
macro. Keep using\label
statements as before.That's all there is to it. :-)
The title of your posting actually was, "How to set a picture with caption in table?" (emphasis added) You may be wondering why I have so far not mentioned a method that involves a table-like structure. It turns out that one could -- but I would strongly argue that one should not -- lift the code that generates figures 3 and 4 above and place it inside a
tabular*
environment (and replace\hspace{\fill}
with&
):You may verify for yourself that this code produces the exact same output as the earlier, also non-floating, code. I hope you can convince yourself that incurring the extra overhead generated by encasing the two
minipage
environments inside atabular*
environment is pointless and undesirable.