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 prefer to design my figures externally such that I only need to include one image in latex, even if it consist in several subfigures. Say, I want to have two figures (a) and (b) side by side. Instead of creating two images (corresponding to (a) and (b)) and including both in the figure environement, I rather create one image with both figures side by side and include only this one in the figure environement.

However, I sometimes did proceed the other way round and came to appreciate the handiness of the subfig package that, together with cleveref, allows direct and automated referencing of subfigures.

Still, I want to stick to my habit of creating one image rather than two, because I can more easily adjust the position of the subfigures. Is there a way to reference a subfigure that is not explicitely defined as such in latex (because it is defined externally)?

I know that I could do this by hand with using \ref and putting an "a" or "b" behind. However, I don't know yet, if I want to have my references in parenthesis or not and this can be easily adjusted by the cleveref package at the end. Therefore, I want to keep it as homogeneous as possible.

I am sorry if there is already such a question, but I have absolutely no idea how to search for this. Using my title in the search field does give any clue.

share|improve this question
5  
I think the workflow you're describing is going to cause frustration in the long run. Personally, I would create one figure per image, and then use the subfigure environment from the excellent subcaption package. You can then globally change all of your captions easily, and easily use the cleverref package too. –  cmhughes Jun 4 '12 at 21:11
    
My subcaption package allows labeling build-in subfigures, see tex.stackexchange.com/questions/40508/… –  Axel Sommerfeldt Jun 5 '12 at 6:11

1 Answer 1

up vote 4 down vote accepted

I agree that this workflow is not ideal, but one way you can work with what you have is to use empty subfigure environments from the subcaption package. I made a new command called \phantomsubfigure that accepts a label for the subfigure as the only argument.

Code:

\documentclass[]{article}

\usepackage[demo]{graphicx} %the demo option is set only for this example
\usepackage[]{hyperref}
\usepackage[]{cleveref} %http://www.ctan.org/pkg/cleveref
\usepackage[labelformat=empty,skip=0pt]{subcaption} %http://www.ctan.org/pkg/subcaption

\newcommand*\phantomsubfigure[1]{\begin{subfigure}[]{0pt}\caption{}\label{#1}\end{subfigure}} %<---- this is the command

\begin{document}

Take look at the cow in \cref{1a}, the space ship in \cref{1b}, and finally at the dress in \cref{1c}.

\begin{figure}[ht]
\centering
\includegraphics[width=\columnwidth]{test.jpg}%
\phantomsubfigure{1a}%
\phantomsubfigure{1b}%
\phantomsubfigure{1c}%
\caption{this is a test}
\end{figure}

\end{document}

Example Output:

example output

share|improve this answer
    
Thanks, works fine for my purpose. And maybe I should reconsider my workflow, but not for the next two weeks :). How do you usually work? Do you create an image for each subfigure, with same dimensions? Or at least same height? How do you align them? Just by inserting some \hfill? Thanks in advance. –  Berserk Jun 4 '12 at 23:27
1  
Yes, I create an image for each subfigure. My subfigures are usually data plots from MATLAB with the same dimensions so they basically line themselves up. I usually have two subfigures per row, so I just set the width of each graphic to .5\linewidth. en.wikibooks.org/wiki/LaTeX/… might be able to help on ideas for aligning subfigures. –  JohnReed Jun 5 '12 at 0:23
    
+1 but I think the order of the packages should be graphicx, hyperref, cleveref –  cmhughes Jun 5 '12 at 2:36
    
@cmhughes Thanks for the correction, I've edited the answer to reflect the changes. –  JohnReed Jun 5 '12 at 2:43

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.