我问过类似问题但我没有意识到问题和解决方案依赖于位于底部的标题。
请考虑以下示例:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}
\centering
% from `caption` documentation:
% Please note that `position=top` does NOT mean that the caption is actually placed at the top of the figure or table
% Instead the caption is usually placed where you place the `\caption` command.
\captionsetup[subfigure]{singlelinecheck=false,skip=-6pt,position=top}
\begin{subfigure}{0.4\textwidth}
\caption{}
\includegraphics[width=1.0\textwidth]{example-image-a}
\label{fig:a}
\end{subfigure}
\begin{subfigure}{0.4\textwidth}
\caption{}
\includegraphics[width=1.0\textwidth]{example-image-b}
\label{fig:b}
\end{subfigure}
\end{figure}
\end{document}
这副标题包中提到的选项在caption
文档。在源代码中,\caption{}
应该出现在\includegraphics{...
影响排序之前。不幸的是,这会产生意想不到的影响,即标签被渲染在图形下方,这意味着图形遮挡了它。在示例中,我包含了一个部分遮挡标签的跳过:
如何让标题位于顶部,但位于图中?我开始明白为什么这些答案对于放置在图顶部而不是图底部的标题来说,其难度要大得多。
答案1
必须始终绘制前景后背景,这意味着将标题提升到位。(如果您想知道,TikZ 会自动按顺序分层。)
\caption
必须放在 或 内minipage
,\parbox
并且\vbox
是\setbox0=\vbox{}
将其放在 内的最简单方法\raisebox
。\vbox
从当前环境获取其宽度。
您可以调整\raisebox
来改变位置。
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}
\centering
% from `caption` documentation:
% Please note that `position=top` does NOT mean that the caption is actually placed at the top of the figure or table
% Instead the caption is usually placed where you place the `\caption` command.
\captionsetup[subfigure]{singlelinecheck=false,skip=0pt}%
\begin{subfigure}{0.4\textwidth}
\setbox0=\vbox{\caption{}\label{fig:a}}% label uses local values
\sbox1{\includegraphics[width=1.0\textwidth]{example-image-a}}% measure height
\leavevmode\rlap{\usebox1}% use horizontal overlap
\raisebox{\dimexpr \ht1-\ht0}{\usebox0}
\end{subfigure}\hfil
\begin{subfigure}{0.4\textwidth}
\setbox0=\vbox{\caption{}\label{fig:b}}% label uses local values
\sbox1{\includegraphics[width=1.0\textwidth]{example-image-b}}% measure height
\leavevmode\rlap{\usebox1}% use horizontal overlap
\raisebox{\dimexpr \ht1-\ht0}{\usebox0}
\end{subfigure}
\end{figure}
\end{document}