[Tex/LaTex] Subfigure label position and visibility in memoir

memoirsubfloats

I am writing my master thesis using Memoir. I want all subfigures to have their labels in the top left corner. I have so far done this with tikz, but I would like to find a more elegant solution as my current solution has flaws.

I would like to be able to automatically reference figures in the text, without having to manually specify the subfigure. This means each figure needs to have a label. Yet if I label the subfigure, said label invariably appears underneath the figure, and I am not sure how to move it, change its color and so on.

Anyway, an mwe and images of current and desired solution:

\documentclass{memoir}

\usepackage{tikz,siunitx,mwe}
\newsubfloat{figure}

\newcommand{\scalebarimg}[6]{
  \begin{tikzpicture}
    \draw node[name=micrograph] {\includegraphics[width=#2\textwidth]{#1}}; %I fetch the image
    \draw[ultra thick,#6] (micrograph.south west)++(0.03*0#2\textwidth,0.035*0#2\textwidth)--++(#2*#3\textwidth,0)node[above,midway]{#4 \si{\micro\meter}}; %I draw the scalebar
    \draw  (micrograph.north west)  node[anchor=north west,yshift=-1,#6]{\textbf{\small{(#5)}}}; %I draw the image label
  \end{tikzpicture}
}

\begin{document}
\begin{figure}
\centering
\subbottom[\label{fig:one}]{
    \scalebarimg{example-image}{.45}{0.33933}{50}{a}{black}
}\subbottom[\label{fig:two}]{
    \scalebarimg{example-image}{.45}{0.33933}{50}{b}{white}
}
\caption{Figures (a) and (b) should not be doubly labeled.}
\end{figure}



See Figure~\ref{fig:one} and \subcaptionref{fig:two}.

\end{document}

which yields
enter image description here
but I want
enter image description here

Is there a way of letting LaTeX position the label where I want it to relative the top left corner of the image? Or at least hide the caption for each individual subfigure while still labelling it?

Best Answer

I would use the subcaption package and \phantomsubcaption (or \phantomcaption if you decide to use e.g., subfigure environment). Note that you need version 1.1 of the subcaption package. Below is your adapted MME:

\documentclass{memoir}

\usepackage{tikz,siunitx,mwe}
\usepackage{subcaption}
\newsubfloat{figure}

\newcommand{\scalebarimg}[6]{
  \begin{tikzpicture}
    \draw node[name=micrograph] {\includegraphics[width=#2\textwidth]{#1}}; %I fetch the image
    \draw[ultra thick,#6] (micrograph.south west)++(0.03*0#2\textwidth,0.035*0#2\textwidth)--++(#2*#3\textwidth,0)node[above,midway]
    {#4 \si{\micro\meter}}; %I draw the scalebar
    \draw  (micrograph.north west)  node[anchor=north west,yshift=-1,#6]{\textbf{\small{#5}}}; %I draw the image label
  \end{tikzpicture}
}

\begin{document}
\begin{figure}
   {\phantomsubcaption\label{fig:one}
   \scalebarimg{example-image}{.45}{0.33933}{50}{\subref{fig:one}}{black}}
   {\phantomsubcaption\label{fig:two}
   \scalebarimg{example-image}{.45}{0.33933}{50}{\subref{fig:two}}{white}}
\caption{Figures (a) and (b) should not be doubly labeled.}
\end{figure}

See Figure~\ref{fig:one} and \subcaptionref{fig:two}.

\end{document}

Result of compilation

I surrounded each subfigure with just {} (needed to separate figure from subfigure) but you can put them for example in minipage, subfigure etc. If you want to customise label, see subcaption documentation.