# Automatic referencing of figure subpanels in Latex

I'm trying to have figure legends to multi-panelled figures and reference to the individual subpanels from the text. When I rearrange the panels I don't want to go through all the text and change the panel references. So I tried to work with counters. However there seems to be a bug, which depends on the number of characters before the counter command. If there are too many characters the counter will not start at A, but rather if there are two subpanels in the figure start with C, if there is three subpanels start counting with D, etc. Does anyone know a solution to this particular bug, or in general how to do automatic referencing to figure subpanels?

Thank you!

\documentclass{article}

\begin{document}

\newcounter{FigI}[figure]
\renewcommand{\theFigI}{\Alph{FigI}}

\begin{figure}
\caption{ManyCharactersManyCharactersManyCharactersManyCharacters
\protect\refstepcounter{FigI} \Alph{FigI} \label{mySubPanel_1}  Panel caption
\protect\refstepcounter{FigI} \Alph{FigI} \label{mySubPanel_2} Panel caption}
\end{figure}

\begin{figure}
\caption{FewCharactersFewCharacters
\protect\refstepcounter{FigI} \Alph{FigI} \label{mySubPanel_3}  Panel caption
\protect\refstepcounter{FigI} \Alph{FigI} \label{mySubPanel_4} Panel caption}
\end{figure}

Text: These are references to Figure 1 \ref{mySubPanel_2} and to panel \ref{mySubPanel_1}.

And a ref to Figure 2\ref{mySubPanel_4}.

\end{document}


## migrated from stackoverflow.comDec 1 '15 at 15:19

This question came from our site for professional and enthusiast programmers.

• why not using the subfig or subfloat package? – Bordaigorl Dec 1 '15 at 16:32
• Welcome to TeX.SE! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Dec 1 '15 at 19:11