[Tex/LaTex] How to give any figure a caption based on its horizontal size

captionsfloatsindentation

I have figures in both portrait and landscape and of various sizes. I'm trying to find a leeway to give any figure a caption based on its horizontal size. In my thesis.cls file, I've already set a general form as \usepackage[centerlast,small,sc,bf]{caption} and \setlength{\captionmargin}{20pt}. Is there a smart way to do that?

Best Answer

Yes, there is. Use the floatrow package and its \ffigbox command. (This package cooperates well with the caption package.)

\documentclass{article}

\usepackage[centerlast,small,sc,bf]{caption}
\setlength{\captionmargin}{20pt}

\usepackage{floatrow}

\begin{document}

\begin{figure}
\ffigbox[\FBwidth]{%
  \rule{8cm}{4cm}%
}{%
  \caption{Hello, here is some text without a meaning.}%
}%
\end{figure}

\begin{figure}
\ffigbox[\FBwidth]{%
  \rule{4cm}{8cm}%
}{%
  \caption{Hello, here is some text without a meaning.}%
}%
\end{figure}

\end{document}

enter image description here