3

I want the caption for each subfigure to be on one line because it isn't so long that it should line-wrap. Is there any way I can force it to be on one line?

Here is a minimum working example:

\documentclass[a4paper,12pt]{article}

\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{epstopdf}

\begin{document}
These captions will look very bad.
\begin{figure*}[thp!]
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \centerline{\includegraphics[height=8cm, width = 13cm]{file.eps}}
        \caption{This long caption should fit on one line still}
    \end{subfigure}
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \centerline{\includegraphics[height=8cm, width = 13cm]{file.eps}}
        \caption{This long caption should also fit on one line}
    \end{subfigure}%
\end{figure*}

\end{document} 
Mico
  • 506,678

3 Answers3

1

Change the {0.5\textwidth} to {1\textwidth}

Im still not sure exactly what this does, but this fixed the issue

\documentclass[a4paper,12pt]{article}

\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{epstopdf}

\begin{document}
These captions will look very bad.
\begin{figure*}[thp!]
    \centering
    \begin{subfigure}[t]{1\textwidth}
    \centering
        \centerline{\includegraphics[height=8cm, width = 13cm]{file.eps}}
        \caption{This long caption should fit on one line still}
    \end{subfigure}
    \begin{subfigure}[t]{1\textwidth}
    \centering
        \centerline{\includegraphics[height=8cm, width = 13cm]{file.eps}}
        \caption{This long caption should also fit on one line}
    \end{subfigure}%
\end{figure*}

\end{document} 
0

Since the two graphs are each 13 centimeters wide, I would set the widths of the two subfigure environments to 13 centimeters as well. I'm assuming that you would want the subcaptions to be as wide as the associated graphs, but no wider.

You can then omit the two \centerline wrappers and as well as two \centering instructions inside the subfigure environments. I'd also omit the [t] positioning qualifiers for the subfigure environments, as they do nothing except add code clutter.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{epstopdf}

\begin{document}
These captions no longer look bad.

\begin{figure}[thp!]
\centering
    \begin{subfigure}{13cm}
        \includegraphics[height=8cm, width = \linewidth]{file.eps}
        \caption{This long caption fits on one line}
    \end{subfigure}

    \bigskip  % create some vertical separation between the subfigures
    \begin{subfigure}{13cm}
        \includegraphics[height=8cm, width = \linewidth]{file.eps}
        \caption{This long caption also fits on one line}
    \end{subfigure}
\end{figure}

\end{document} 
Mico
  • 506,678
0

You can set the width of the caption or sub-captions of a figure by using commands \captionsetup{width=0.6\linewidth} and \captionsetup[subfigure]{width=0.6\linewidth}, respectively. If you use the mentioned commands in the preamble, the option is applied to all figures you have in the document. You can also use them in a specific figure you want to change the width of its captions. For more details see how to resize the width of subcaption and Setting subcaption width for specific subcaptions .

Venus
  • 120