# Hard space in figure/table caption

I have a problem with figure captions. Since I have very long words in figure and table captions (names of chemical compounds) the space between caption label, caption number and first word of caption is not constant. It looks like this:

While I would like to have hard space between caption label, caption number and first word of caption so it would look more or less like this:

I am using own document class I didn't put any code for captions there except of two lines in the preamble:

\usepackage[labelfont=bf]{caption}
\captionsetup{labelsep=period}

a piece of code from class that may be of some importance for the question:

\def\@baseclass{report}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@baseclass}}
\PassOptionsToClass{a4paper,twoside,openright,12pt}{\@baseclass}
\ProcessOptions

Is there a simple way to do it (get hard spaces in the caption label)?

• would avoiding such problems in the first place by allowing hyphenation of those long words not be the better option here? – greyshade Aug 27 '14 at 11:57
• @greyshade -- hyphenation of chemical terminology might introduce confusion, since components of a compound are already distinguished by separating them with hyphens. if it's permitted, a better (looking) option here would be to set the caption ragged right. – barbara beeton Aug 27 '14 at 13:34
• barara beeton's suggestions can simply be enabled by adding justification=raggedright to the options list of the caption package. – justibus Aug 27 '14 at 13:40
• @barbarabeeton it might introduce confusion, but it seems to be a commonly discussed question (e.g. here, here) and the bpchem package provides very fine grained control over it, so any ambiguity might be avoided as the OP sees fit. – greyshade Aug 27 '14 at 13:47
• @barbarabeeton Hyphenation is pretty common in chemical names: it's more-or-less required to get IUPAC ones to fit in a lot of places! – Joseph Wright Sep 3 '14 at 13:04

Perhaps one of these solutions will be more or less what you want: I defined a hardspace caption label format that ensures a normal space between caption name and caption number. A fixed space between label and first word can be achieved with the RaggedRight option (which enables some hyphenation). However, as the whole caption is centred with respect to text width, its placement may look odd, depending on the effective width of the figure, and it may be better to have caption width equal to figure width and have caption on the left side rather than centred. This can be achieved with the measuredfigure environment from the threeparttable package.

So I propose 4 variants, according to justification and use of this environment or not:

\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{caption}
\usepackage{threeparttable}

\DeclareCaptionLabelFormat{hardspace}{\mbox{#1~#2}}
\DeclareCaptionLabelSeparator{hardspace}{.~}
\captionsetup{labelformat = hardspace, labelfont = bf,justification = RaggedRight}
\usepackage[demo]{graphicx}

\usepackage{chngcntr}
\renewcommand\thesection{\Alph{section}}
\counterwithin{figure}{section}
\setcounter{section}{1}
\setcounter{figure}{21}

\begin{document}
\noindent\texttt{Justification = RaggedRight: }

\begin{figure}[!h]
\centering
\begin{measuredfigure}
{\includegraphics[width =0.9\linewidth]{myfigure}}
\caption{The $\prescript{1}{}{\text{H-NMR}}$ spectrum of \textbf{12},4-bis(2,2’-bithienyl-(4-hydroxypenyl)methane thymine-1-acetate, in deuterated chloroform.}
\end{measuredfigure}
\end{figure}

\begin{figure}[!h]
\centering
\includegraphics[width =0.9\linewidth]{myfigure}
\caption{The $\prescript{1}{}{\text{H-NMR}}$ spectrum of \textbf{12},4-bis(2,2’-bithienyl-(4-hydroxypenyl)methane thymine-1-acetate, in deuterated chloroform.}
\end{figure}

\clearpage
\noindent\texttt{Justification = justified: }

\captionsetup{justification = justified}
\begin{figure}[!h]
\centering
\begin{measuredfigure}
{\includegraphics[width =0.9\linewidth]{myfigure}}
\caption{The $\prescript{1}{}{\text{H-NMR}}$ spectrum of \textbf{12},4-bis(2,2’-bithienyl-(4-hydroxypenyl)methane thymine-1-acetate, in deuterated chloroform.}
\end{measuredfigure}
\end{figure}

\begin{figure}[!h]
\centering
\includegraphics[width =0.9\linewidth]{myfigure}
\caption{The $\prescript{1}{}{\text{H-NMR}}$ spectrum of \textbf{12},4-bis(2,2’-bithienyl-(4-hydroxypenyl)methane thymine-1-acetate, in deuterated chloroform.}
\end{figure}

\end{document}

• Thank you very much, I really appreciate your time to post this answer. – Marta Sep 4 '14 at 8:24
• The space inserted with ~ is flexible; you get a hard space with something like \hspace{0.33em}. – egreg Sep 4 '14 at 11:26
• @egreg: Do you mean it can be quite large under special circumstances? I didn't know that: for me, an unbreakable space was a ‘normal’ interword space. – Bernard Sep 4 '14 at 12:03