到目前为止,我尝试了使用(i)minipage 和(ii)表格环境的两个 Ansatzes:
%(i) minipage
\begin{figure}[htp]
\begin{minipage}[t]{0.5\textwidth}
\vspace{0pt}
\includegraphics{figures/general_model/dummy}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
\vspace{0pt}
\caption{ This is the caption to my dummy figure. It is very informative. I like rainy weather. I am too lazy to include lorem lipsum.} \label{fig:segments}
\end{minipage}%
\end{figure}
和
%(ii) tabular
\begin{figure}[htp]
\begin{tabular}{p{0.5\textwidth} p{0.45\textwidth}}
\vspace{0pt}
\includegraphics{figures/general_model/dummy}
&
\vspace{0pt}
\caption{ This is the caption to my dummy figure. It is very informative. I like rainy weather. I am too lazy to include lorem lipsum.}
\end{tabular}
\end{figure}
两者都产生相同的行为:
我一直在手动绘制红色虚线来标记图像的顶部边缘。
我怎样才能将标题与图像的顶部边缘对齐,如下所示:
我更希望使用表格或小页面来回答问题,避免包含新库。提前致谢!
答案1
不使用任何包,以下定义了一个名为的环境sidecap
,它接受一个可选参数和一个强制参数(就像\caption
),并将标题排版到环境内容的右侧。标题将获得与行上剩余空间相同的空间,长度可自定义\sidecap@sep
。
\documentclass[]{article}
\usepackage[]{graphicx}
\makeatletter
\newsavebox\sidecap@box
\newlength\sidecap@sep
\setlength\sidecap@sep{10pt}
\NewDocumentEnvironment {sidecap} { O{#2} m }
{%
\begin{lrbox}{\sidecap@box}%
}
{%
\end{lrbox}%
\mbox
{%
\raisebox{-\height}{\usebox\sidecap@box}%
\hskip\sidecap@sep
\raisebox{-\height}
{%
\setlength\abovecaptionskip\z@
\parbox{\dimexpr\linewidth-\wd\sidecap@box-\sidecap@sep}%
{\caption[{#1}]{#2}}%
}%
}%
}
\makeatother
\usepackage{duckuments}% <- dummy content
\begin{document}
\blindduck[full]
\begin{figure}
\begin{sidecap}{A lovely duck.\label{fig:duck}}
\includegraphics{example-image-duck}%
\end{sidecap}
\end{figure}
\begin{figure}
\begin{sidecap}{Another lovely duck for which I need to tell you so much that
my caption will get a bit too long to fit in a single line.\label{fig:ducky}}
\includegraphics{example-image-duck}%
\end{sidecap}
\end{figure}
\blindduck[full]
\end{document}
第一个浮动:
第二个浮点数:
答案2
使用tabularray
、adjustbox
和caption
包:
\documentclass{article}
\usepackage[export]{adjustbox} % for "valign", also load graphicx
\usepackage{tabularray}
\UseTblrLibrary{varwidth} % <===
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{lipsum}
\begin{document}
\begin{figure}[htp]
\begin{tblr}{colspec={X[c] X[j,t]}}
\includegraphics[width=\linewidth,valign=t]{example-image-duck}
& \captionsetup{skip=-\abovecaptionskip}
\caption{\lipsum[1][2-4].}
\end{minipage}
\end{tblr}
\end{figure}
\end{document}
答案3
评论中提到斯基尔蒙,对于两种环境,设置abovecaptionskip
都可以解决问题:
\begin{figure}[htp]
\begin{minipage}[t]{0.5\textwidth}
\vspace{0pt}
\includegraphics{figures/general_model/dummy}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
\vspace{0pt}
\setlength{\abovecaptionskip}{0pt}
\caption{ This is the caption to my dummy figure. It is very informative. I like rainy weather. I am too lazy to include lorem lipsum.} \label{fig:segments}
\end{minipage}%
\end{figure}