Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a figure with three subfigures shown in the code sample below. How can I change the reference to a subfigure so that I have Figure 1 (left), Figure 1 (center), and Figure 1 (right) instead of figure 1.1, 1.2, and 1.3? Also, in the caption I would like to it to have a general caption, then in the same paragraph have (left) left's caption (center) center's caption (right) right's caption.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure*}
\begin{minipage}[b]{0.33\linewidth}
\label{fig:left}
\includegraphics[width=2.5in,height=2.5in]{img1}
\end{minipage}
\begin{minipage}[b]{0.33\linewidth}
\includegraphics[width=2.5in,height=2.5in]{img2}
\label{fig:center}
\end{minipage}
\begin{minipage}[b]{0.33\linewidth}
\includegraphics[width=2.5in,height=2.5in]{img3}
\label{fig:right}
\end{minipage}
\caption{
    Blah blah blah.  
    \ref{fig:left} blah blah.   
    \ref{fig:center} blah blah.   
    \ref{fig:right} blah blah.
}
\label{fig:all}
\end{figure*}
\end{document}
share|improve this question
    
Your code snippet doesn't include any captions for each of the figures, yet you say you want Figure 1 (left), Figure 1 (center) and Figure 1 (right). Is this correct... you want these captions? Are you using hyperref? Why don't you just type \caption{Blah blah blah. (left) blah blah. (center) blah blah. (right) blah blah.}? –  Werner Sep 18 '12 at 5:07
    
I'd simply write the caption as \caption{Blah blah. Left: blahleft. Center: blahcenter. Right: blahright.} –  egreg Sep 18 '12 at 15:52
    
That's basically how I've done it right now, but it would be nice to be able to reference the left/center/right pictures within a paragraph. –  Mike Izbicki Sep 18 '12 at 18:06
    
I've sometimes done this by using \label for the overall figure, which presents the three subfigures as (a), (b), and (c). Then, when I reference the left figure in the text, I would use \ref{fg:figlabel}a. Correspondingly, \ref{fg:figlabel}b for the middle and \ref{fg:figlabel}c for the right figure. –  Steven B. Segletes Feb 22 '13 at 14:32
add comment

migrated from stackoverflow.com Sep 18 '12 at 14:28

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

1 Answer

up vote 2 down vote accepted

In what follows, a new numbering system called \lcr is defined (which works the same way as \arabic, \alph, etc. do) that associates "left" to "1", "centre" to "2", and "right" to "3".

The prettyref package is then used to customise the cross-referencing to either of the three "subfigures". Note that \phantomsubcaption must be used in order to create an anchor for \ref.

\documentclass{article}

\makeatletter
\def\lcr#1{\expandafter\@lcr\csname c@#1\endcsname}% LaTeX
\def\@lcr#1{%
  \ifnum#1=0%
    \@ctrerr% 
  \else\ifnum#1=1%
      left%
    \else\ifnum#1=2%
       center%
     \else\ifnum#1=3%
        right%
      \else
        \@ctrerr%
      \fi
    \fi
  \fi
}
\makeatother

\usepackage{subcaption}

\DeclareCaptionSubType*{figure}
\renewcommand\thesubfigure{\thefigure~(\lcr{subfigure})}

\usepackage{prettyref}
\newrefformat{subfiglcr}{Figure~\ref{#1}}

\usepackage{tikz}
%\usepackage{graphicx}

\begin{document}

\begin{figure*}
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=red,fill=red!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:left}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=green,fill=green!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:center}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=blue,fill=blue!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:right}
    \end{minipage}
    \caption{Three squares. Left: red. Center: green. Right: blue.}
    \label{fig:all}
\end{figure*}

\prettyref{subfiglcr:left} shows a typical example of red square;
\prettyref{subfiglcr:center} shows a particularly interesting specimen of green square,
while \prettyref{subfiglcr:right} shows a common and rather unremarkable blue square.

\end{document}

enter image description here

In this example, the tikz package is used instead of the graphicx package (used by the OP), in order to generate some placeholder pictures.

share|improve this answer
add comment

Your Answer

 
discard

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.