I have several pairs of graphs. I need to display these graphs in latex. I am using the following which works Great.
\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
\centering
\fbox{\includegraphics[width=.8\linewidth]{4-byVar1.png}}
\caption{``Here's a question?'' (by Var1)}
\label{fig:4-byVar1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\fbox{\includegraphics[width=.8\linewidth]{4-byVar2.png}}
\caption{``Here's a question?'' (by Var2)}
\label{fig:4-byVar2}
\end{subfigure}
\caption{``Here's a question?''}
\label{fig:comboFig-4}
\end{figure}
However, that's a lot of code to repeat for each such pair of figures. I created a
\newcommand
to do the work for me, but it seems that when I try to ref a figure created by my newcommand, i get an error (fig undefined).
Can anyone recommend how I can refer to a label created by a newcommand?
The newcommand I created looks like this
\newcommand{\graphPairs}[2]{
\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
\centering
\fbox{\includegraphics[width=.8\linewidth]{#2-byCar1.png}}
\caption{#1 (by Var 1)}
\label{fig:#2-byVar1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\fbox{\includegraphics[width=.8\linewidth]{#2-byVar2.png}}
\caption{#1 (by Var 2)}
\label{fig:#2-byVar2}
\end{subfigure}
\caption{#1}
\label{fig:comboFig-#2}
\end{figure}
}
fig:comboFig-5would correspond to calling your command with the 2nd argument being{5}so loading images5-byCar1.pngand5-byVar1.pngis that what you did? it always help if your question contains complete runnable documents that demonstrate the problem. – David Carlisle Nov 27 '12 at 17:59