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.

\newcommand\fig[2]{
\includegraphics[width=3in]{#2}
\phantomsection
\label{#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!!!

-

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

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


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

-

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

\newcommand{\myfig}[2]
{\refstepcounter{figure}%%'
\includegraphics[width=2in]{#2}%%'
\phantomsection
\label{#1}%%'
}


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

\usepackage{amsmath}
\numberwithin{figure}{section}

-
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