Align figure and caption

captionsfloats

I am novice on LaTeX, and I tried to align figure and caption. But This happens. What should I do? Especially caption Graph1 is looking bad so I want to align with the square figure.

I am finding information from here, with the same problem, but I can find nothing at all like me…

\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\centering
\begin{subfigure}[normal]{0.4\textwidth}
\includegraphics[width=0.6\textwidth]{36.jpg}
\caption{Graph1}
\end{subfigure}
\begin{subfigure}[normal]{0.4\textwidth}
\includegraphics[width=0.8\textwidth]{37.jpg}
\caption{Graph2}
    
\end{subfigure}

\caption{Two graphs for tests.}

\end{figure}


\end{document}

enter image description here

Best Answer

  • Sine you prescribe smaller width of images than is width of subfigure, you need to insert \centering instruction in each subfigure.
  • Please avoid to use H figure position options. It can cause unexpected problems, when is not sufficient palce in page, where image is inserted.
\documentclass[12pt]{article}

\usepackage[demo]{graphicx}
\usepackage{caption,
            subcaption}

\begin{document}

\begin{figure}[ht]
\centering
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=0.6\textwidth]{36.jpg}
\caption{Graph1}
\end{subfigure}
%\hfil
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=0.8\textwidth]{37.jpg}
\caption{Graph2}
\end{subfigure}

\caption{Two graphs for tests.}
\end{figure}

\end{document}

enter image description here