[Tex/LaTex] How to place multiple pdf figures next to each other in Latex

floatspdftexsubfloats

I have four charts which were originally in eps file format. I have exported them as pdfs and I am trying to include them next to each other and under each other.

I have the following code

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{testing}
\author{abc}
\date{}
\usepackage{lscape}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{epstopdf}
\begin{document}

\maketitle

\begin{figure}%
    \centering
    \subfloat[label 1]{\includegraphics[scale=0.25]{mat_density_r1.pdf}}%
    \qquad
    \subfloat[label 2]{\includegraphics[scale=0.25]{mat_density_r2.pdf}}%
    \newline
    \subfloat[label 1]{\includegraphics[scale=0.25]{mat_density_r3.pdf}}%
    \qquad
    \subfloat[label 2]{\includegraphics[scale=0.25]{mat_density_r4.pdf}}%
    \caption{2 Figures side by side}%
    \label{fig:example}%
\end{figure}

\end{document}

I have two issues:

  1. I am not able to see the images

  2. They are not aligned

picture of rendering

I am not getting any errors in overleaf and I am not sure what I am doing wrong.

Best Answer

Well, there are four problems here:

  1. your used \newline is wrong here. Replace it simply with a blank line
  2. you used option [demo] for package graphicx. Omit it.
  3. you do not need package epstopdf here for your issue
  4. I changed the double labels 1 and 2 to 3 and 4

So with the following code

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{testing}
\author{abc}
\date{}
\usepackage{lscape}
\usepackage{subfig}
\usepackage{graphicx}
%\usepackage{epstopdf}


\begin{document}

\maketitle

\begin{figure}%
    \centering
    \subfloat[label 1]{\includegraphics[scale=0.25]{example-image-a}}%
    \qquad
    \subfloat[label 2]{\includegraphics[scale=0.25]{example-image-b}}%

    \subfloat[label 3]{\includegraphics[scale=0.25]{example-image-c}}%
    \qquad
    \subfloat[label 4]{\includegraphics[scale=0.25]{example-image-a}}%
    \caption{2 Figures side by side}%
    \label{fig:example}%
\end{figure}

\end{document}

you get the result:

enter image description here