# Post or pre note using \ref

The figures I intend to include in my latex files are sometimes splitted into subfigures and labeled accordingly (e.g. have an (a), (b), etc marker), but still a single figure. This makes it easier for me to align them properly (labels (a) and (b) on the same height etc.). When I reference them in the text, I use something like \ref{fig:my_face}(a). Using the hyperref package, the text linked includes only the figure number of course, not the (a) as well. Is there a way to include a post- or prenote like the cite command does (e.g. \cite[p. 99]{myRef} links the p.99 as well)?

The following code

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}

\begin{figure}
\includegraphics{fig.pdf}
\caption{
Some caption.
}
\label{fig:test}
\end{figure}

\ref{fig:test}(a)

\end{document}


produces the output

I like to have the (a) also link to the image, so it should in appear in red too.

• Doesn't subfig or subcaption package provide this feature already?
– user31729
Jan 19 '16 at 10:31
• Yes, but I would have to provide multiple figures for that. I have my subfigures within a single figure. Jan 19 '16 at 10:40
• It would be extremely helpful if you could provide a compilable example!
– user31729
Jan 19 '16 at 10:58

You can use a combination of a manual \hyperref and \ref*, wrapped inside a macro:

\documentclass{scrreprt}
\usepackage{graphicx}

\newcommand{\myref}[2][]{\hyperref[#2]{\ref*{#2}#1}}

\begin{document}

\begin{figure}
\centering