Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a document with a few sections, I'm new to LaTeX so I'm just using the article class. I want the figure numbers to restart in each section. I did this with \setcounter{figure}{0} at the start of each section, and I figure this is somehow related to (causing) my problem but I just can't figure out a solution.

The problem is when I click on a hyper-link in a figure reference to, say, Figure 1 in Section 2, it will take you back to the first figure one (back in Section 1 in this case), even if the reference specifies the correct figure by name/label.

I'm using XeLaTeX and the multicols environment so I've included that in my MWE but I don't think they are related to the problem. I'm also using a custom \Figure so that the figure fits in the column nicely.

Here is the MWE:

\documentclass[10pt, letterpaper]{article} 
\usepackage{geometry} 
\geometry{letterpaper, hmargin=1.5in, vmargin=1in, marginparsep=7pt, marginparwidth=.6in}
\usepackage{multicol}
\usepackage[small,bf,hypcap=false]{caption}
\usepackage{graphicx}
\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}  
\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}
\begin{document}

\begin{multicols}{2}[\section*{section1}]
(Figure~\ref{fig:fig1}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\captionof{figure}{caption}
\label{fig:fig1}
\end{Figure}
\end{multicols}

\newpage
\setcounter{figure}{0}
\begin{multicols}{2}[\section*{section2}]
(Figure~\ref{fig:fig2}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\captionof{figure}{caption}
\label{fig:fig2}
\end{Figure}
\end{multicols}

\end{document}

Here is a compiled PDF for your convenience: http://dl.dropbox.com/u/3730003/mwe6.pdf

To easily witness the problem, go to the 2nd page and click on the hyperlink in the reference to the figure, it will take you back to the first page.

I've been trying to use:

\renewcommand*{\theHfigure}{\arabic{section}.\arabic{figure}} 

after the start of each section and this works if I use section{} instead of section*{} but with 'section*' the 'section' number stays at 0 with \arabic{section} and \thesection.

Note: I'm not completely sure what hypcap=false does but I was getting errors from the caption package with the default hypcap=true so I switched it to false but it doesn't seem to change anything.

share|improve this question
    
Is there a particular reason that you want to use unnumbered sections? –  qubyte Feb 27 '12 at 5:46
    
This is for a short document, specifically a job application package, with a cover-letter, cv, and research proposal, just don't want/need to number each of the sections. –  s0rce Feb 27 '12 at 6:06
    
Silly question; have you tried using \phantomsection before your \section*{...} commands? I think this may increment the necessary counters without extra effort. –  qubyte Feb 27 '12 at 6:16
    
Ah, no. Sorry, I'm seeing the problem now. –  qubyte Feb 27 '12 at 6:20
1  
For the non-working hyperlink see: tex.stackexchange.com/questions/45935/… –  Axel Sommerfeldt Feb 27 '12 at 7:02
add comment

2 Answers

The problem with your current approach is that the hyperlink is being duplicated- as you'll see in your log file,

destination with the same identifier (name{figure.1}) has been already used, duplicate ignored

You can get round this by deleting the \setcounter{figure}{0} and adding

\makeatletter
     \@addtoreset{figure}{section}
\makeatother

to your preamble- this resets the figure number every section, and keeps hyperlinks working the way you want. This method works for uses of \section but does not work for \section*... perhaps someone knows how to implement the reset for \section*?

A complete MWE follows

\documentclass{article} 
\usepackage{geometry} 
\usepackage{multicol}
\usepackage[small,bf,hypcap=false]{caption}
\usepackage[demo]{graphicx}
\usepackage{hyperref}  
\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}

\makeatletter
    \@addtoreset{figure}{section}
\makeatother

\begin{document}

\begin{multicols}{2}[\section{section1}]
(Figure~\ref{fig:fig1}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\captionof{figure}{caption}
\label{fig:fig1}
\end{Figure}
\end{multicols}

\newpage
\begin{multicols}{2}[\section{section2}]
(Figure~\ref{fig:fig2}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\captionof{figure}{another caption}
\label{fig:fig2}
\end{Figure}
\end{multicols}

\end{document}
share|improve this answer
    
:( It's not working for me, the figure number doesn't reset in each new section. –  s0rce Feb 27 '12 at 3:42
    
@s0rce try it now- replaced with \section* with \section- do you need it to reset with \section* as well? –  cmhughes Feb 27 '12 at 4:00
    
Yes, I do need that. I don't want numbered sections, well at least I don't want the number to show up in the document. ` \@addtoreset{figure}{section*}` doesn't appear to work. –  s0rce Feb 27 '12 at 4:04
    
I could manually \addtocounter{section}{1} after each \section* but it would be nice if one command at the beginning could do everything! This should do the trick: \newcommand{\unnumsec}[1]{\refstepcounter{section}\section*{#1}} –  s0rce Feb 27 '12 at 4:17
1  
@s0rce are you sure you want your numbers to reset in section* as well? this is going to make referencing them quite hard, both from the author and the reader perspective... –  cmhughes Feb 27 '12 at 18:27
add comment
up vote 2 down vote accepted

Thanks to Two table counters and hyperref links and hide section numbering but continue adding-up for the ideas and the help of @cmhughes's answer. I am now using this combination which seems to work well.

I put in a new section command unnumsec which replicates section* while incrementing the section counter:

\newcommand{\unnumsec}[1]{\refstepcounter{section}\section*{#1}}

Now the code from @cmhughes will work properly to reset the figure counter:

\makeatletter
     \@addtoreset{figure}{section}
\makeatother

And to ensure that hyperlinks point correctly to figures with the same number in different sections I put this just after \begin{document}

\renewcommand*{\theHfigure}{\arabic{section}.\arabic{figure}}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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