TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a few command that allows me to reference figures inside a table and add the reference to the table of contents.

\addcontentsline{toc}{subsection}{Figure \ref{#1} #1}

This is what I have tried, but the figure number does not seem to increment.

My goal is to generate something like in the screenshot below. Thanks for your help!!!

enter image description here

share|improve this question

If you use the capt-of package (just one line of code) then you don't need \refstepcounter and \addtocontents simply do

... &
\captionof{figure}{the caption}\label{myfig}
& ...

and the figure will be captioned and added to the list of figures in the normal way.

share|improve this answer

The problem is how you're advancing the counter. You need to be using \refstepcounter to get the label to refer to the correct figure number.

Incidentally, you are allowing a lot of extra white space into your command. Try

   \addcontentsline{toc}{subsection}{Figure \ref{#1} #1}%%'

To get figures to be numbered within sections as you image seems to suggest you need to add two lines to your preamble.

share|improve this answer
I think \csname phantomsection \endcsname is preferred. – Jesse Aug 31 '13 at 4:10
@jesse I'm not sure I follow. \csname phantomsection \endcsname should do the same thing as \phantomsection; it's just a lot of typing. – A.Ellett Aug 31 '13 at 21:17
indeed that is what I know of, but that produces an error while i follow your direction to try. Later on, i tried csname method and the error disappeared, thus the comment. – Jesse Sep 1 '13 at 1:24
@Jesse Now I understand your point. \csname ....\endcsname doesn't throw an error if the command name is not defined. The OP did not list all of the packages needed for his example. \phantomsection is a command defined in the hyperref package. If you load that package, then you should be able cut and paste my example without error. – A.Ellett Sep 1 '13 at 1:29
It is clear now. Thanks for the remark above. – Jesse Sep 1 '13 at 1:41

Your Answer


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.