2

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}

Label is partially under the image.

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:

enter image description here

What would be the most elegant solution to get the z-order correct?

  • Re-reading your question, I'm not sure whether you want the sinking to be there. Do you just want a better way to place the labels or just remove the sinking using the current solution? – Alenanno Jan 16 '18 at 12:44
  • Sorry for the confusing description. I have added an image of the desired result. – egonz Jan 16 '18 at 12:51
1

While slightly overkill, you can use TikZ, along with \phantomsubcaption and \subref, to do this:

output of code

\documentclass{article}
\usepackage{tikz} % loads graphicx and xcolor

\usepackage{caption}
\usepackage{subcaption}
\renewcommand\thesubfigure{\Alph{subfigure}}

\begin{document}

\begin{figure}
  \centering
  {\phantomsubcaption\label{fig:1a}}
  {\phantomsubcaption\label{fig:1b}}
  \tikz\node[inner sep=0pt,label={[anchor=north west]north west:\subref{fig:1a}}] {\textcolor{gray}{\rule{5cm}{3cm}}};
  \tikz\node[inner sep=0pt,label={[anchor=north west]north west:\subref{fig:1b}}] {\textcolor{gray}{\rule{5cm}{3cm}}};

  \caption{This is Figure 1.}\label{fig:1}
\end{figure}
\end{document}

Or ...

Good ol' picture mode.

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}

\usepackage{caption}
\usepackage{subcaption}
\renewcommand\thesubfigure{\Alph{subfigure}}

\begin{document}

\begin{figure}
  \centering
  \setlength\unitlength{1cm}
  {\phantomsubcaption\label{fig:1a}}
  {\phantomsubcaption\label{fig:1b}}

\textcolor{gray}{\rule{5cm}{3cm}}%
\begin{picture}(0,0)
\put(-4.8,2.6){\subref{fig:1a}}
\end{picture}
\textcolor{gray}{\rule{5cm}{3cm}}%
\begin{picture}(0,0)
\put(-4.8,2.6){\subref{fig:1b}}
\end{picture}

\caption{This is Figure 1.}\label{fig:1}
\end{figure}
\end{document}
|improve this answer|||||
  • Thanks! I agree that the TikZ approach seems a bit of an overkill. I think I'll fake it with picture in those few cases where I really need it. – egonz Jan 17 '18 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.