2

I'm trying to set up a figure, so that it contains 2 subfigures. I would prefer if I could set them up with an A and B in the left-top corner (outside of the figure). However, I would also want to be able to reference each subfigure in my text. I have searched for a lot of different solutions, but I haven't been able to put together anything that works, so I'll try with a question.

Here's my MWE:

\documentclass[a4paper,11pt]{book} 
\usepackage{subcaption} 
\usepackage[export]{adjustbox} 
\usepackage{cleveref} 

\begin{document}
\begin{figure}[tb]
\centering

\begin{subfigure}[t]{0.03\textwidth}
    \textbf{A}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
    \includegraphics[width=\linewidth,valign=t]{"test1"}
    \label{subfigure1}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.03\textwidth}
    \textbf{B}  
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
    \includegraphics[width=\linewidth,valign=t]{"test1"}
    \label{subfigure2}
\end{subfigure}

\caption{Here's a nice caption}. \label{overall label}
\end{figure}

Me trying to reference the entire figure: Figure \ref{overall label}. 
Me trying to reference the first subfigure A: Figure \cref{subfigure1}.
Me trying to reference the first subfigure B: Figure \cref{subfigure2}.
\end{document}

It looks something like this

Subfigure reference problem

I think I've got the part covered with the letters (even though I have to manually assign the letters). However, I can not get the subfigure reference to work.

I'm sorry if it seems messy. I'm not particularly adept with LaTeX. I hope someone will be able to help out!

  • Welcome to TeX.SE! See if http://tex.stackexchange.com/questions/20354/sidesubfloats-why-does-this-errored-code-work-and-my-correct-code-doesnt solve your problem. – Zarko May 17 '16 at 15:31

1 Answers1

2

I suspect that you like to have something like this:

enter image description here

It is adopted from answer sidesubfloats:

\documentclass{article}
\usepackage{floatrow}
\usepackage{graphicx}
%\usepackage{subfig}
\usepackage[label font=bf,labelformat=simple]{subfig}% <-- changed
\usepackage{caption}
\floatsetup[figure]{style=plain,subcapbesideposition=top}

\begin{document}
    \begin{figure}[htb]\centering
\sidesubfloat[]{\includegraphics[width=0.4\textwidth]{example-image-a}\label{fig:a}}
\hfil
\sidesubfloat[]{\includegraphics[width=0.4\textwidth]{example-image-b}\label{fig:b}}
\caption{Main caption}
    \label{fig:myfigure}
    \end{figure}
Figure \ref{fig:myfigure} consist three sub figures: \ref{fig:a} and \ref{fig:b}     
\end{document}

Addendum: Sub captuion layout you can determine by subfig options. They are summarized in subfig documentation, page 8. If you replace

\usepackage{subfig}

with

\usepackage[label font=bf,labelformat=simple]{subfig}

than subcaptions will look as show new image.

Zarko
  • 296,517
  • Excellent answer! It solves many of my problems. I, however, have a new one: Will it be possible to change the labeling of my subfigures from (a) and (b) to a bold-fontet A and B? And also make this appear in my text when I reference them? So it says "Figure 1 consists three subfigures: 1A and 1B"? – Andreas Redsted May 17 '16 at 16:15
  • well, this is additional/new question ... :-). of course, it is possible. See subfig documentations for options which it offer. I can do this latter evening. – Zarko May 17 '16 at 16:17
  • That would be much appreciated! I have checked the documentations for both floatrow and subfig, I now know how to make the captions bold, but not how to get rid of the parenthesis and make it capital letters. – Andreas Redsted May 17 '16 at 17:07
  • The \usepackage[label font=bf,labelformat=simple]{subfig} did the trig, I will upgrade my answer. – Zarko May 17 '16 at 17:15
  • Is there any way to adjust the size of the letters a and b, while maintaining the bold font? – Andreas Redsted May 17 '16 at 18:11
  • Yes, it is. I look the subfig documentation again :-) and found option: font=<size>, where you can select size from \scriptsize to \Large. – Zarko May 17 '16 at 19:46
  • I tried that myself! Because of the noob I am, I did not know I needed to add the . Thank you for that. However, when I add it, it tells me my TeX capacity is exceeded. Any way to work around this. Here's the error:
    "TeX capacity exceeded, sorry [input stack size=5000]. \usepackage" 
    
    

    The code I use is:

    \usepackage[font=\Large,labelfont=bf,labelformat=simple]{subfig}
    
    

    Thanks for all your help so far!

    – Andreas Redsted May 18 '16 at 08:34
  • I'm very sorry to misleading you regarding font size (i didn't tested before posting). For font size you should use only scriptsize to Large. This work fine. For example, that you like to have Lare fonts for sub captions, than \usepackage[labelfont=bf,labelformat=simple,font=Large]{subfig} did the trick. Of course, you can use caption set up for settings of subfig options: \captionsetup[subfloat]{labelfont=bf,labelformat=simple,font=Large}. – Zarko May 18 '16 at 10:02