1

I am using the following code to place two subfigures:

\documentclass[a4paper, 12pt]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\newcommand{\rulesep}{\unskip\ \vrule\ }
  \begin{document}
    \begin{figure}[H]
      \centering
        \begin{subfigure}{.48\linewidth}
        \centering
        \includegraphics[width=\linewidth]{subfigure_1.jpeg}
        \caption[caption]{This is the caption\\Isosurface corresponding to \, $\lambda_{2,m} = -3$.}
        \label{subfig1}
        \end{subfigure} 
        \hfill
        \rulesep
        \begin{subfigure}{.48\linewidth}
        \centering
        \includegraphics[width=\linewidth]{subfigure_2.jpeg}
        \caption[caption]{This is the caption\\Isosurface corresponding to \, $\lambda_{2,m} = -3$.}
        \label{subfig2}
        \end{subfigure}
        \caption{Figure 1}
        \end{figure}
  \end{document}

The output of this code is:

enter image description here As one can see the sub captions are not appearing at the center of the subfigure.

I want both the lines of the caption to be at the center of the subfigure. I would like to have something similar to this: enter image description here

Can someone please tell me how can I do this?

  • Please show a compilable minimal example so that we can use for testing (the current one is very close to being compilable, but you also need \documentclass, and we don't have subfigure_1.jpeg and subfigure_2.jpeg) – fractal Dec 22 '19 at 13:31
  • I am sorry that it is a bit difficult to provide the subfigures. I am restricted in that regard. I am really sorry for this inconvenience. – Giri Dec 22 '19 at 13:38
  • No problem. You can use example-image (or example-image-duck - recommended), and set width and height so that it can illustrate the size of your images. – fractal Dec 22 '19 at 13:39
  • 1
    Now I have included the dimensions in the problem description. – Giri Dec 22 '19 at 13:57
  • (Reply to comment in deleted answer) @Giri No, the problem is not the subscript. The problem is that if the caption is a bit long, the justification is lost. For now I will delete the answer and dig in it a little more. – fractal Dec 22 '19 at 14:22
3

Like this?

enter image description here

(red rules indicate text area borders)

\documentclass[12pt]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{figure}[ht]
  \centering
  \setkeys{Gin}{width=\linewidth,height=95mm}
  \captionsetup[subfigure]{justification=centerlast}
  \begin{subfigure}{65mm}
    \includegraphics{example-image}
    \caption[Short caption]{Top view.\\ Isosurface corresponding to $\lambda_{2,m} = -3$}
    \label{subfig1}
  \end{subfigure}
  \hfil
  \begin{subfigure}{65mm}
    \includegraphics{example-image-duck}
    \caption[Short caption]{Top view.\\ Isosurface corresponding to \mbox{$\lambda_{2,m} = -3$}
    \label{subfig2}
  \end{subfigure}
  \caption{Figure 1}
\end{figure}
\end{document}
| improve this answer | |
  • As previously said by @Fractal, the problem is that if the caption is a bit long, the justification is lost. My subcaption looks like \caption[caption]{Top view.\\Isosurface corresponding to $\lambda_{2,m} = -3$} – Giri Dec 22 '19 at 15:25
  • You might throw in a [singlelinecheck=false] just to show it doesn't matter. – John Kormylo Dec 22 '19 at 16:06
  • @Giri, it is not clear, how you like to have centered captions, sorry. Now I guessing, that you maybe like to have centered it if they occupy just one line and centered only the last line in case of multi line caption. Or you like to have caption narrower than image? Elaborate please. – Zarko Dec 22 '19 at 16:17
  • @JohnKormylo can you please tell where am I supposed to include [singlelinecheck=false] ? – Giri Dec 22 '19 at 16:18
  • @Giri - It is one of the \captionsetup options. See page 9 of the caption manual. – John Kormylo Dec 22 '19 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.