1

I would like to put the caption of each subfigure in the center of the subfigure but it appears to the left. Do you know how can I move the caption of the subfigures and also the caption of the Figure? Thanks in advanced!

    \begin{figure}[h]

\centering

\begin{subfigure}{.5\textwidth}

  \centering

  \includegraphics[width=.4\linewidth]{Non-State.png}

  \caption{Non-State Violence}

  \label{fig:sub1}

\end{subfigure}%

\begin{subfigure}{.5\textwidth}

  \centering

  \includegraphics[width=.4\linewidth]{One-Sided.png}

  \caption{One Sided violence}

  \label{fig:sub2}

\end{subfigure}

\begin{subfigure}{.5\textwidth}

  \centering

  \includegraphics[width=.4\linewidth]{State-Based.png}

  \caption{State-Based Violence}

  \label{fig:sub3}

\end{subfigure}

\caption{Type of Violence}

\label{fig:test}

\end{figure}

enter image description here

5
  • Welcome to TeX.SE. Your code produces two, not three, subfigures. Moreover, the subfigures are necessarily placed below each other and centered. Please clarify.
    – Mico
    Commented Feb 14, 2021 at 10:35
  • You are completely right. I put another code, I am sorry. What I want is to put the subtitle of each figure just down of each subfigure, not to the left of the subfigure.
    – OgeiD
    Commented Feb 14, 2021 at 10:40
  • 1
    With the information you provided so far, I can not reproduce the output you get. If I take your code fragment and turn it into a compilable minimal working example (MWE), the captions are centered with respect to the individual images. I can only reproduce the output you get, if I add \usepackage{caption} \captionsetup{singlelinecheck=false} to the preamble of my MWE. Could it be possible, that thouse two lineas are also present in your document. If so, try removing the \captionsetup{singlelinecheck=false}.
    – leandriis
    Commented Feb 14, 2021 at 10:45
  • For me, the code works. I have added \usepackage[justification=centering]{caption} and now I obtain the result I want. Thank you for the answer!
    – OgeiD
    Commented Feb 14, 2021 at 10:48
  • 2
    The main point that @leandriis was making is that the code you posted automatically centers single-line subcaptions. There's no need for the justification=centering option unless the captions' widths exceed that of the underlying subfigure environments. But, elsewhere, you've indicated that that's not the case.
    – Mico
    Commented Feb 14, 2021 at 11:17

2 Answers 2

1

This should work:

\documentclass[demo]{article} % remove 'demo' option in real document
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[justification=centering]{caption}

\begin{document}

\begin{figure}[h]
  %\centering
  \begin{subfigure}{.42\textwidth}
    %\centering
    \includegraphics[width=\linewidth]{Graph1.png}
    \caption{"Stable" Countries group}
    \label{fig:sub1}
  \end{subfigure}
  \hfill
  \begin{subfigure}{.42\textwidth}
    %\centering
    \includegraphics[width=\linewidth]{Graph2.png}
    \caption{"unstable" Countries group}
    \label{fig:sub2}
  \end{subfigure}
  \caption{Number of Actors by Year and Countries}
  \label{fig:test}
\end{figure}

\end{document}

Edit: I took Mico's advice so long captions align better with the graphic.

7
  • Did you try to compile this code? AFAICT, it doesn't load a package that defines \includegraphics. Please clarify.
    – Mico
    Commented Feb 14, 2021 at 10:36
  • It works with \usepackage[justification=centering]{caption}. Thank you!
    – OgeiD
    Commented Feb 14, 2021 at 10:41
  • 1
    With this setup, captions that take up multiple lines will also be horizontally centered.
    – leandriis
    Commented Feb 14, 2021 at 10:46
  • 1
    This approach lets the width of the longer subcaptions exceed that of the associated graphs. Probably not a good outcome. Better to set \begin{subfigure}{.0.42\textwidth} (b/c 0.6*0.7=0.42) and [width=\linewidth]. That way, the captions' widths can be no greater than that of the graphs.
    – Mico
    Commented Feb 14, 2021 at 10:49
  • 1
    +1 for the edits. I've taken the liberty of editing your code some more in order to provide some horizontal separation between the subfigures. Feel free to revert.
    – Mico
    Commented Feb 14, 2021 at 11:12
1

The best way I can think to achieve your formatting objective is to change [width=.6\linewidth] to [width=\linewidth] and, if necessary, to change the widths of the subfigure environments.

enter image description here

\documentclass[demo]{article}
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}[h]
\centering

\begin{subfigure}{.45\textwidth}
\includegraphics[width=\linewidth]{Graph1.png}
\caption{Non-state violence}
\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\linewidth]{Graph2.png}
\caption{One-sided violence}
\label{fig:sub2}
\end{subfigure}

\bigskip
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\linewidth]{Graph3.png}
\caption{State-based violence}
\label{fig:sub3}
\end{subfigure}

\caption{Types of violence}
\label{fig:test}

\end{figure}
\end{document}
4
  • Thank you for the answer. What I have done is what was suggested by ttnick: write \usepackage[justification=centering]{caption} and it works. Thank you again for the answer. I will keep it!
    – OgeiD
    Commented Feb 14, 2021 at 10:47
  • @OgeiD - I guess it depends on how one defines "it works". If letting the widths of longer captions exceed that of the associated graphs can be called "it works", I suppose you're right.
    – Mico
    Commented Feb 14, 2021 at 10:52
  • Hahaha, good comment. Probably, you are right. For me, It works means that it solves what I wanted to do with that figure. Maybe in other cases it will not be a solution.
    – OgeiD
    Commented Feb 14, 2021 at 10:57
  • @Zarko - Many thanks. I've only just now noticed that there was an issue in the opening sentence. Hopefully, that's now fixed.
    – Mico
    Commented Feb 14, 2021 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .