We have table caption background image. We put this as image. But we need the table caption and images exactly same width as table body.
[Tex/LaTex] Table caption Width
captionsfloatstableswidth
Related Solutions
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. :-)
\documentclass{article}
\usepackage{caption} % for \captionof macro
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\begin{document}
Here's a cross-reference to Figure~\ref{fig:star2}.
\hrule % just to illustrate the width of the text block
%% a floating version
\begin{figure}[h!]
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{first.pdf}
\caption{A cloud} \label{fig:cloud1}
\end{minipage}
\hspace{\fill}
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{second.pdf}
\caption{A star} \label{fig:star1}
\end{minipage}
\end{figure}
%% a non-floating version
\noindent % override any \parindent effect
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{third.pdf}
\captionof{figure}{Another cloud} \label{fig:cloud2}
\end{minipage}
\hspace{\fill}
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{fourth.pdf}
\captionof{figure}{Another star} \label{fig:star2}
\end{minipage}
\end{document}
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 &
):
\noindent
\begin{tabular*}{\textwidth}{@{} l @{\extracolsep{\fill}} r @{}}
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{fifth.pdf}
\captionof{figure}{Still another cloud} \label{fig:cloud3}
\end{minipage}
&
\begin{minipage}{0.48\textwidth}
\includegraphics[width=1\linewidth]{sixth.pdf}
\captionof{figure}{Still another star} \label{fig:star3}
\end{minipage}
\end{tabular*}
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 a tabular*
environment is pointless and undesirable.
% arara: pdflatex
% arara: pdflatex
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[spanish]{babel}
\usepackage{float}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{blindtext}
\usepackage{siunitx}
\usepackage{amssymb}
\begin{document}
\listoftables
\section{cualquier cosa}
\blindtext
\begin{table}[H]
\centering
\caption[Duración de procesamiento del método entero]{Duración de procesamiento del método entero (Carga, Pre-proce"-sa"-mien"-to, Procesamiento). Tiempos en segundos. Paralelizado con OpenMP. Promedio de $5$ corridas}
\label{cuadroMetodo}
\small
\begin{tabular}{%
c
S[table-format=5.3, group-four-digits=true]
S[table-format=5.3, group-four-digits=true]
S[table-format=5.3, group-four-digits=true]
S[table-format=4.3]
S[table-format=4.4]
S[table-format=4.4]}
\toprule
{Tam.\ imagen (px)} & {$1$ hilo} & {$2$ hilos} & {$4$ hilos} & {$6$ hilos} & {$8$ hilos} & {$10$ hilos} \\
\midrule
$50 \times 50$ & 0.968 & 0.577 & 0.434 & 0.332 & 0.287 & 0.36 \\
$100 \times 100$ & 4.31 & 2.232 & 1.253 & 0.927 & 0.75 & 0.922 \\
$200 \times 200$ & 18.93 & 9.655 & 5.159 & 3.553 & 2.701 & 3.243 \\
$500 \times 500$ & 128.809 & 64.267 & 33.142 & 23.219 & 17.106 & 20.649 \\
$1000 \times 1000$ & 519.442 & 262.823 & 137.123 & 93.391 & 69.318 & 82.22 \\
$2000 \times 2000$ & 2118.952 & 1071.719 & 541.691 & 376.155 & 278.819 & 331.238 \\
$5000 \times 5000$ & 13404.611 & 6677.812 & 3392.367 & 2368.776 & 1754.587 & 2078.983 \\
$10000 \times 10000$ & 53261.461 & 26872.99 & 13591.092 & 9433.897 & 7022.0824 & 8115.5902 \\
\bottomrule
\end{tabular}
\end{table}
\addtocounter{table}{-1}
\begin{table}[H]
\centering
\captionsetup{list=no}
\caption{Duración de procesamiento del método entero (Carga, Pre-proce"-sa"-mien"-to, Procesamiento). Tiempos en segundos. Paralelizado con OpenMP. Promedio de $5$ corridas (\emph{Continuación})}
\small
\begin{tabular}{%
c
S[table-format=4.3]
S[table-format=4.3]
S[table-format=4.3]
S[table-format=4.3]
S[table-format=4.3]}
\toprule
{Tamaño imagen (px)} & {$12$ hilos} & {$14$ hilos} & {$16$ hilos} & {$18$ hilos} & {$20$ hilos} \\
\midrule
$50 \times 50$ & 0.375 & 0.3 & 0.316 & 0.356 & 0.388 \\
$100 \times 100$ & 0.807 & 0.791 & 0.772 & 0.822 & 0.865 \\
$200 \times 200$ & 2.927 & 2.823 & 2.726 & 2.727 & 2.86 \\
$500 \times 500$ & 17.895 & 17.195 & 16.667 & 16.759 & 16.782 \\
$1000 \times 1000$ & 73.805 & 69.338 & 66.73 & 67.28 & 67.02 \\
$2000 \times 2000$ & 293.657 & 281.142 & 268.252 & 270.269 & 268.739 \\
$5000 \times 5000$ & 1872.82 & 1746.592 & 1683.274 & 1685.559 & 1689.839 \\
$10000 \times 10000$ & 7360.177 & 6945.76 & 6742.854 & 6740.288 & 6757.892 \\
\bottomrule
\end{tabular}
\end{table}
\blindtext
\end{document}
Best Answer
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: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
: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
This works well with images. Tables might be harder as object, but in your case you could refer to your background images.