0

So far I tried two Ansatzes using (i) minipage and (ii) tabular environment:

%(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}  

and

%(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}  

Both yield the same behavior:

enter image description here

I have been drawing the red dotted line manually to mark the top edge of the image.

How can I align the caption with the top edge of the image like so:

enter image description here

I would prefer answers using tabular or minipage and avoid including new libraries. Thanks in advance!

newandlost
  • 51
  • 4

3 Answers3

0

With use of the tabularray, adjustbox and caption packages:

\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}

enter image description here

Zarko
  • 296,517
0

Without any packages, the following defines an environment called sidecap that takes an optional argument and a mandatory one (just like \caption) and will typeset the caption to the right of the contents of the environment. The caption will get as much space as there is left on the line with a customizable separation of the length \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}

First float:

enter image description here

Second float:

enter image description here

Skillmon
  • 60,462
0

Like was mentioned in the comments by Skillmon, setting abovecaptionskip does the trick, for both environments:

\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}  
newandlost
  • 51
  • 4