0

I have used the subfigures package but there is a slight misalignment between my two captions. The figures however are aligned and of identical size. Would anyone know how I can solve this ?

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
  \frenchbsetup{StandardLists=true}
\usepackage{caption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{pgf, tikz}
  \usetikzlibrary{patterns}
  \usetikzlibrary{fit,arrows,calc,positioning}
\usepackage{pgfplots}
  \pgfplotsset{width=8.5cm,compat=1.9,legend style={font=\scriptsize}}
\usepackage{subcaption}

\begin{document}

\begin{figure}[H]
  \caption{Progression de la proportion d'élèves dans les groupes de niveaux dans l'item "Comprendre des phrases lues par l'adulte" selon l'année (en pourcentage)}
  \begin{subfigure}{0.5\textwidth}
    \caption{Groupe "satisfaisant"}
    \begin{tikzpicture}
      \begin{axis}[height=1.2\textwidth, width=1\textwidth,
        legend style={font=\scriptsize},
        legend pos=south east,
        legend image post style={solid},
        nodes near coords,
        every node near coord/.append style={font=\scriptsize},
        nodes near coords align={vertical},
        xtick={1,2},
        xticklabels={Septembre, Février},
        every tick label/.append style={font=\scriptsize},
        ]
        \addplot+ [
        sharp plot,
        ] coordinates {
        (1,82.1) (2,83.6)
        };
        \addplot+ [
        sharp plot,
        ] coordinates {
        (1,84) (2,83.7)
        };
      \legend{2018-2019, 2019-2020}
      \end{axis}
    \end{tikzpicture}
  \end{subfigure}
  \begin{subfigure}{0.5\textwidth}
    \caption{Groupe "en difficulté"}
    \begin{tikzpicture}
      \begin{axis}[height=1.2\textwidth, width=1\textwidth,
        nodes near coords,
        every node near coord/.append style={font=\scriptsize},
        nodes near coords align={vertical},
        ymax=4,
        xtick={1,2},
        xticklabels={Septembre, Février},
        every tick label/.append style={font=\scriptsize},
        ]
        \addplot+ [
        sharp plot,
        ] coordinates {
        (1,3.5) (2,3)
        };
        \addplot+ [
        sharp plot,
        ] coordinates {
        (1,3) (2,3.1)
        };
      \end{axis}
    \end{tikzpicture}
  \end{subfigure}
\end{figure}

\end{document}

Subcaptions (a) and (b) are not aligned

Many thanks ! :)

4
  • I feel like it is cause by the height of the number in ymax. I have removed both "ymax" options but the automatically chosen ymax is still higher in one side, thus still causing the same problem.
    – Manon Cha
    Jan 24 at 14:48
  • My tests revealed that setting ymax=4.5 resolves the issue. And BTW the subfigures aren't aligned themselves.
    – Ronald
    Jan 24 at 14:49
  • I'm surprised this fit into one line. Dit they add \ignorespaces at the end of subfigure? Jan 24 at 20:07
  • I didn't, the code I've pasted is the code I'm using.
    – Manon Cha
    Jan 28 at 10:41

1 Answer 1

1

Just update your code with [t] option as:

\begin{subfigure}[t]{0.5\textwidth}

And the problem is solved.

1
  • Thanks! I would never have found it by myself.
    – Manon Cha
    Jan 28 at 10:43

You must log in to answer this question.

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