user2260180
user2260180

Reputation: 275

latex float caption first letter capital, rest lower case

I am trying to force the first letter of a caption ot be uppercase, and the rest lower case. There seems to be a clash between xstring and subfig (that I need)

\documentclass{article}                     
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{xstring}
% Redefine \caption command to capitalize the first letter
\let\oldcaption\caption
\renewcommand{\caption}[1]{%
\StrLeft{#1}{1}[\firstletter]%
\StrGobbleLeft{#1}{1}[\therest]%
\oldcaption{\MakeUppercase\firstletter\MakeLowercase{\therest}}%
}
\begin{document}
\begin{figure}[h]
\includegraphics[width=0.5\linewidth]{example-image-a}
\caption{this Is A saMple a sample caption.}
\end{figure}
\end{document}

Upvotes: 1

Views: 272

Answers (0)

Related Questions