Graphics, Figures & TablesHow to put the caption for graphics?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

How to put the caption for graphics?

Post by paulosousa »

Hello all
Need help!
I have no problem with caption (on top) of tables (have 'Tabela 1', ...) and with caption for the figures (have 'Figura 1', ...), but I need to insert some graphics in the document and I must put a caption on top of it with only 'Gráfico 1', 'Gráfico 2'...

Code: Select all

\documentclass[12pt, twoside, a4paper]{article}
\usepackage[portuguese]{babel}
\usepackage[applemac]{inputenc}
\usepackage[left=2.0cm,top=1.5cm,right=2.0cm,bottom=1.75cm]{geometry}
\usepackage{amsmath,amssymb,amsfonts,textcomp,setspace,graphicx,color,environ,tabularx,enumitem}
\usepackage[font=small,labelfont=bf]{caption}

\begin{document}

\begin{table}[h]
\caption{} \label{table:t2}
\centering 
\small
\vspace{-0.20cm}
\begin{tabular}{|c|c|c|c|c|c|}
\toprule
\textbf{Partido} & \hspace{0.35cm} A \hspace{0.35cm} & \hspace{0.25cm} B \hspace{0.25cm} & \hspace{0.25cm} C \hspace{0.25cm}  & \hspace{0.25cm} D \hspace{0.25cm} & \hspace{0.25cm} E \hspace{0.25cm}  \\ 
\midrule
\textbf{Número de votos} & 594  & 418  & 89  &  563 &  71  \\ 
\bottomrule
\end{tabular} 
\end{table}

\begin{figure}[h]
\begin{center}
\includegraphics[scale=0.450]{figures/3/img1.png}
\captionof{figure}{}
\label{figure:usf}
\end{center}
\end{figure} 

\end{document}
Should I use something like this?

Code: Select all

\addto\captionsportuguese{
%\renewcommand{\graphicname}{Gráfico}
}
I appreciate any help! Thanks a lot.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10329
Joined: Mon Mar 10, 2008 9:44 pm

How to put the caption for graphics?

Post by Stefan Kottwitz »

Hi,

use:

\addto\captionsportuguese{\renewcommand{\figurename}{Gráfico}}

And within a figure or table environment use \centering instead of \begin{center} ... \end{center}, such as

Code: Select all

\begin{figure}[htbp!]
\centering
\includegraphics[scale=0.450]{figures/3/img1.png}
\caption{Test}
\label{figure:usf}
\end{figure}
If the caption should go to the top of the graphics, move \caption before \includegraphics. By the way, the more placement options for figures, the easier and the closer the placement, that's why I often use htbp!.

Stefan
LaTeX.org admin
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

How to put the caption for graphics?

Post by paulosousa »

Stefan,

thanks a lot for the suggestion concerning the use of \centering and tomove \caption before \includegraphics
Concerning the suggestion to use \addto\captionsportuguese{\renewcommand{\figurename}{Gráfico}}...
this way I will rename all caption to 'Gráfico n' but in whole doc I need 'Figura 1', 'Figura 2' and 'Gráfico 1'...
How should I do?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10329
Joined: Mon Mar 10, 2008 9:44 pm

How to put the caption for graphics?

Post by Stefan Kottwitz »

Ah, I understand. Like this:

Code: Select all

\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=grf,placement={!htbp},
  name=Gráfico,listname={List of Gráficos},]{grafico}
...
\listofgraficos
...
\begin{grafico}[htbp!]
\centering
\includegraphics[scale=0.450]{figures/3/img1.png}
\caption{Test}
\label{grafico:usf}
\end{grafico}
Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to put the caption for graphics?

Post by Johannes_B »

https://tex.stackexchange.com/questions ... cate-float
This is an example for a diagram, you just need to replace the name with what you want.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

How to put the caption for graphics?

Post by paulosousa »

Now it's perfect, thanks a lot Stefan.
Stefan Kottwitz wrote:Ah, I understand. Like this:

Code: Select all

\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=grf,placement={!htbp},
  name=Gráfico,listname={List of Gráficos},]{grafico}
...
\listofgraficos
...
\begin{grafico}[htbp!]
\centering
\includegraphics[scale=0.450]{figures/3/img1.png}
\caption{Test}
\label{grafico:usf}
\end{grafico}
Stefan
Post Reply