I am trying to place labels (A, B, C…) onto the top-left corners of subfigures. I tried it with caption/subcaption packages and by defining a negative skip like \captionsetup[sub]{skip=-5pt}
, but the labels are typeset under the figure. Here is what I got right now:
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[sub]{labelfont=bf, position=top,
singlelinecheck=false, labelformat=simple, skip=-5pt}
\renewcommand\thesubfigure{\Alph{subfigure}}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.45\linewidth}
\caption{}\label{fig:1a}
\textcolor{gray}{\rule{5cm}{3cm}}
\end{subfigure}
\begin{subfigure}{.45\linewidth}
\caption{}\label{fig:1b}
\textcolor{gray}{\rule{5cm}{3cm}}
\end{subfigure}
\caption{This is Figure 1.}\label{fig:1}
\end{figure}
\end{document}
As you can see, A and B are hiding behind the grey box, but I would like to have them rendered on top. The desired result would be like this:
What would be the most elegant solution to get the z-order correct?
Best Answer
While slightly overkill, you can use TikZ, along with
\phantomsubcaption
and\subref
, to do this:Or ...
Good ol'
picture
mode.