1

I would like that captions be justified at left, but following the size os figures. I am using this code:

\documentclass[12pt,a4paper]{article}
(...)
\usepackage{float}
 \usepackage[justification=raggedright,singlelinecheck=off,margin=1.5cm,format=hang,font=footnotesize,labelsep=endash]{caption}
 \begin{document}
 \begin{figure}[!ht]%[H]
\begin{center}
    \caption{Temperatura média em MG}
    \includegraphics[scale=0.715]{clima_mg.JPG}
    \caption*{\scriptsize{Fonte: Scolforo \textit{et al.} (2008)}} 
    \label{climamg}
\end{center}
 \end{figure}

blablablablablabla
blablablablablabla
\begin{figure}[!ht]%[H]

\begin{center}
\caption{Gride 5 por 5}
    \begin{tabular}{|c|c|c|c|c|}
    \hline 
    &  &  & &   \\ 
    \hline 
    &  &  & &    \\ 
    \hline 
    &  &  & &  \\ 
    \hline 
    &  &  & &\\ 
    \hline 
    &  &  & &\\ 
    \hline 
    \end{tabular} 
\end{center}
\caption*{\scriptsize{Fonte: Elaboração própria}}
\label{grid}
 \end{figure}

Result:

enter image description here

How can I set the captions to be flexible?

0

A I understood your question, you like to have caption above figure in width of figure and starting at left border of figure. The same for table.

One way to obtain this is use minipage in which you enclose figure or table. At figure you can then define its widths with widths of minipages, at table you need to measure width of table.

With this approach you will obtain something like this:

enter image description here

As you can see, at narrow tables or figures, result is not very pleasant ...

For notes about their source below figure/table I suggest to use the copyrightbox package.

\documentclass[12pt,a4paper]{article}
\usepackage[demo]{graphicx}   % in real document delete option "demo"
\usepackage{copyrightbox}   % <---
\makeatletter
\renewcommand{\CRB@setcopyrightfont}%    <---
    {\scriptsize\color{gray}}
\makeatother
\newsavebox{\tabbox}   % <---
\newlength{\tabwidth}   % <---
\usepackage[justification=raggedright,
            singlelinecheck=off,    
            font=footnotesize,
            labelsep=endash]{caption}   % <---
 \begin{document}
 \begin{figure}[!ht] 
\centering
\begin{minipage}{0.8\linewidth}   % <---
    \caption{Temperatura média em MG}
    \label{climamg}
    \copyrightbox[b]{\includegraphics[width=\linewidth]{clima_mg.JPG}}   % <---
                    {Fonte: Scolforo \textit{et al.} (2008)}   % <---
\end{minipage}    
    \end{figure}

blablablablablabla
blablablablablabla
    \begin{figure}[!ht] 
\sbox{\tabbox}{\begin{tabular}{|c|c|c|c|c|}   % <---
    \hline
  0 & 1 & 2 & 3 & 4 \\
    \hline
    &   &   &   &   \\
    \hline
    &   &   &   &   \\
    \hline
    &   &   &   &   \\
    \hline
    &   &   &   &   \\
    \hline
    \end{tabular}}
\setlength{\tabwidth}{\wd\tabbox}   % <---
\centering
\begin{minipage}{\tabwidth}   % <---
\caption{Gride 5 por 5}
\label{grid}
\copyrightbox[b]{\usebox\tabbox}{Fonte: Elaboração própria}   % <---
\end{minipage}
    \end{figure}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.