我正在尝试将标签(A、B、C...)放置在子图的左上角。我尝试使用 caption/subcaption 包并定义负跳过,例如\captionsetup[sub]{skip=-5pt}
,但标签排版在图形下方。这是我现在得到的结果:
\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}
如您所见,A 和 B 隐藏在灰色框后面,但我想将它们渲染到顶部。 期望的结果如下:
使 z 顺序正确的最优雅的解决方案是什么?
答案1
虽然有点过度,但您可以使用 TikZ 以及\phantomsubcaption
和\subref
来做到这一点:
\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}
或者 ...
很好的旧picture
模式。
\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}