Graphics, Figures & Tables\caption of figure problem

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
kudzu
Posts: 3
Joined: Sun Jan 24, 2010 11:40 am

\caption of figure problem

Post by kudzu »

Hello,
I use clrscode package and when I put at the same page this second caption of figure

Code: Select all

\begin{figure}[ht]
\begin{codebox}
\Procname{$\proc{Dijkstra}(G,w,s)$}
\li $\proc{Initialize-Single-Source}(G,s)$
\li $S \gets \emptyset $
\li $Q \gets V[G]$
\li \While $Q\neq \emptyset$
\li \Do $u \gets \proc{Extract-Min}(Q)$
\li $S \gets S \cup \{u\}$
\li \For każdy wierzchołek $v\in Adj[u]$
\li \Do $\proc{Relax}(u,v,w)$
\End
\End
\end{codebox}
\caption{Algorytm Dijkstry\label{Dijkstra} \cite{Cormen}}
\end{figure}

\begin{figure}[ht]
\caption{A picture of a tucan.\label{ISS}}
\begin{codebox}
\Procname{$\proc{Initialize-Single-Source}(G,s)$}
\li \For każdy wierzchołek $v\in V[G]$
\li \Do $d[v] \gets \infty$
\li $\pi [v] \gets NIL$
\End
\li $d[s] \gets 0$
\end{codebox}
\end{figure}
I get error

Code: Select all

pdfTex warning (ext4): destination with the same identifier (name{figure.0.3}) has been already used, duplicate ignored

\AtBegShi@Output ...ipout \box \AtBeginShipoutBox   \fi \fi
I read about this something, but still I don't understand how to fix it. In new empty project this code goes ok. I'm using WinEDT 5.3

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\caption of figure problem

Post by localghost »

You must not put the label into the caption itself. You have to place it after the caption.

Code: Select all

\caption[Algorytm Dijkstry \cite{Cormen}]{Algorytm Dijkstry}\label{fig:Dijkstra}
The way you put the label generates the same anchor for the hyperref package thus produces the warning.


Best regards and welcome to the board
Thorsten
kudzu
Posts: 3
Joined: Sun Jan 24, 2010 11:40 am

\caption of figure problem

Post by kudzu »

It's not working for me. To put the \label in caption I found in some tutorial that says this make us sure the label is after caption.

When I make the code like this, nothing changed.

Code: Select all

\begin{figure}[ht]
\begin{codebox}
\Procname{$\proc{Dijkstra}(G,w,s)$}
\li $\proc{Initialize-Single-Source}(G,s)$
\li $S \gets \emptyset $
\li $Q \gets V[G]$
\li \While $Q\neq \emptyset$
\li \Do $u \gets \proc{Extract-Min}(Q)$
\li $S \gets S \cup \{u\}$
\li \For każdy wierzchołek $v\in Adj[u]$
\li \Do $\proc{Relax}(u,v,w)$
\End
\End
\end{codebox}
\caption{Algorytm Dijkstry}
\end{figure}

\begin{figure}[ht]
\caption{A picture of a tucan}
\begin{codebox}
\Procname{$\proc{Initialize-Single-Source}(G,s)$}
\li \For każdy wierzchołek $v\in V[G]$
\li \Do $d[v] \gets \infty$
\li $\pi [v] \gets NIL$
\End
\li $d[s] \gets 0$
\end{codebox}
\end{figure}
only when I remove the caption from second figure everything is ok. Or it only looks ok.


UPDATE. When I put a lot of text between this two figures and the second of them goes to next pages everything is ok.
So the question: It is not possible to put second figure with caption on the same page or what i should do to make this right?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\caption of figure problem

Post by localghost »

I don't see the problem. The following works flawlessly for me.

Code: Select all

\listfiles
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{clrscode}
\usepackage{hyperref}

\begin{document}
  \begin{figure}[!ht]
    \begin{codebox}
      \Procname{$\proc{Dijkstra}(G,w,s)$}
      \li $\proc{Initialize-Single-Source}(G,s)$
      \li $S \gets \emptyset $
      \li $Q \gets V[G]$
      \li \While $Q\neq \emptyset$
      \li \Do $u \gets \proc{Extract-Min}(Q)$
      \li $S \gets S \cup \{u\}$
      \li \For każdy wierzchołek $v\in Adj[u]$
      \li \Do $\proc{Relax}(u,v,w)$
      \End
      \End
    \end{codebox}
    \caption{Algorytm Dijkstry}\label{fig:dijkstry}
  \end{figure}

  Figure \ref{fig:dijkstry} shows an algorithm.

  \begin{figure}[!ht]
    \begin{codebox}
      \Procname{$\proc{Initialize-Single-Source}(G,s)$}
      \li \For każdy wierzchołek $v\in V[G]$
      \li \Do $d[v] \gets \infty$
      \li $\pi [v] \gets NIL$
      \End
      \li $d[s] \gets 0$
    \end{codebox}
    \caption{A picture of a tucan}\label{fig:tucan}
  \end{figure}
\end{document}
Please show the opposite by means of a minimal working example (MWE).
kudzu
Posts: 3
Joined: Sun Jan 24, 2010 11:40 am

Re: \caption of figure problem

Post by kudzu »

Here comes the MWE.
Attachments
MasterThesis(latex).zip
(1.28 MiB) Downloaded 185 times
Post Reply