0

I have two subfigures where the right one is vertically above the left one. I am not sure how to fix this. Here is the code I have:


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}% Change the margins here if you wish.
\setlength{\parindent}{0pt} % This is the set the indent length for new paragraphs, change if you want.
\setlength{\parskip}{5pt} % This sets the distance between paragraphs, which will be used anytime you have a blank line in your LaTeX code.
%------------------------------------

% These packages allow the most of the common "mathly things" \usepackage{amsmath,amsthm,amssymb} \usepackage{mathtools} %website \usepackage{hyperref} % This package allows you to add images. \usepackage{graphicx} \usepackage{float} %this is for proper format of quotation. \usepackage{dirtytalk} %algorithm \usepackage{algorithm} \usepackage{algorithmic} % Package for line-spacing (HQ) \usepackage{setspace} \singlespacing % \onehalfspacing % \doublespacing \setstretch{1.1}

%%%% from langevin monte carlo paper %%%%% \usepackage[utf8]{inputenc} % allow utf-8 input \usepackage[T1]{fontenc} % use 8-bit T1 fonts

\usepackage{url} % simple URL typesetting \usepackage{booktabs} % professional-quality tables \usepackage{amsfonts} % blackboard math symbols \usepackage{nicefrac} % compact symbols for 1/2, etc. \usepackage{microtype} % microtypography \usepackage{xcolor} % colors % Added Extra from this point \usepackage{wrapfig} %for wrapping text around figure \usepackage{subcaption} %https://tex.stackexchange.com/questions/645648/environment-subfigure-undefined \usepackage{amsmath} \usepackage{amssymb}

\usepackage{nicefrac} \usepackage{bbm} %for indicator function \usepackage{mathtools} \usepackage{algorithm} \usepackage{algorithmic} % \usepackage[noend]{algpseudocode}

%Format citing % \bibliographystyle{unsrt} \usepackage[comma,authoryear,round]{natbib} \bibliographystyle{plainnat}

% For the table % \usepackage{xcolor} \newcommand\ytl[2]{ \parbox[b]{12em}{\hfill{\color{cyan}\sffamily #1}~$\cdots$~}\makebox[0pt][c]{$\bullet$}\vrule\quad \parbox[c]{10cm}{\vspace{7pt}\raggedright\sffamily #2.\[7pt]}\[-3pt]}

\begin{document}

\begin{figure}[htbp] \begin{subfigure}[t]{0.50\textwidth} \includegraphics[width=\linewidth]{figures/lsvi-phe-DeepSea10.pdf} \caption{Comparison in DeepSea environment}\label{fig:deepsea_best_run_8} \end{subfigure} \hspace*{\fill} % maximize separation between the subfigures \begin{subfigure}[t]{0.50\textwidth} \includegraphics[width=\linewidth]{figures/lsvi-phe-deepsea-Msensitivity.pdf} \caption{Comparison of LSVI-PHE for different $M$ values in DeepSea.}\label{fig:deepsea_sweep_M_sig0.0005} \end{subfigure} \caption{(a) The results are averaged over 5 independent runs and error bars are reported for the return per episode plots. For this plot, $\beta = 5 \times 10^{-3}$ for LSVI-UCB and $\sigma^2 = 5 \times 10^{-5}$ for LSVI-PHE. (b) The results are averaged over 5 runs and error bars are reported for the return per episode plots. For this plot we fix $\sigma^2 = 5 \times 10^{-4}$. } \label{fig:comp-deepsea} \end{figure}

\end{document}

And this is how it looks like:

enter image description here

How can I align them?

  • 1
    Can you provide we can compile (that does not depend on files we do not have) and doesn't have unnecessary stuff in the preamble? Can you reproducing the issue using example-image-a, for instance? If not, are you sure the margins of the images don't differ? – cfr Dec 15 '23 at 18:04
  • I see. thanks, it seems the margin size differs. What solution would you suggest in this case? – melatonin15 Dec 15 '23 at 18:54
  • I'd probably alter the image to remove the white space. If you don't want to do that, you can use the options for \includegraphics. Have a look at the documentation, but you can crop what's shown, though you should be aware that the full image will still be embedded in the PDF. – cfr Dec 15 '23 at 19:31
  • 1
    Off-topic but you should clean up your preamble. Remove packages you aren't using. Avoid loading packages twice. Check the order of loading: you're loading hyperref far too early for it to work without issues. – cfr Dec 15 '23 at 19:34
  • The [t] option of subfigure aligns the first baseline, which is at the bottom of the image. You can align the tops by using \raisebox or the export option of adjustbox and valign. If you want to align both the images and the captions, use a tabular p column. See https://tex.stackexchange.com/questions/646589/misaligned-side-by-side-pictures-how-to-resolve – John Kormylo Dec 15 '23 at 20:13

0 Answers0