side-by-side subfigure in Sharelatex

89,658

I found this code and it is working perfectly for subfigures. For two subfigures use

\begin{figure}%
\centering
\subfigure[Sample1]{%
\label{fig:first}%
\includegraphics[height=2in]{Bilder/sample.png}}%
\qquad
\subfigure[Sample2]{%
\label{fig:second}%
\includegraphics[height=2in]{Bilder/sample.png}}%
\caption{sample}
\end{figure}

with sample output

enter image description here

And for cascading subfigures....

\begin{figure}%
\centering
\subfigure[][]{%
\label{fig:ex3-a}%
\includegraphics[height=2in]{Bilder/sample.png}}%
\hspace{8pt}%
\subfigure[][]{%
\label{fig:ex3-b}%
\includegraphics[height=2in]{Bilder/sample.png}} \\
\subfigure[][]{%
\label{fig:ex3-c}%
\includegraphics[height=2in]{Bilder/sample.png}}%
\hspace{8pt}%
\subfigure[][]{%
\label{fig:ex3-d}%
\includegraphics[height=2in]{Bilder/sample.png}}%
\caption[A set of four subfigures.]{A set of four subfigures:
\subref{fig:ex3-a} describes the first subfigure;
\subref{fig:ex3-b} describes the second subfigure;
\subref{fig:ex3-c} describes the third subfigure; and,
\subref{fig:ex3-d} describes the last subfigure.}%
\label{fig:ex3}%
\end{figure}

sample for 4 subfigure

enter image description here

Share:
89,658
Khan Aaqib
Author by

Khan Aaqib

Updated on December 09, 2020

Comments

  • Khan Aaqib
    Khan Aaqib over 3 years

    I am interested to make a figure with multiple subfigures. By some search I found different ways but not working for me. May be I am using shareLatex and others use proper Latex (I don't know very much difference so sorry if I say something odd). Given below is the code...

    \begin{figure}[t!]
        \centering
        \begin{subfigure}[t]{0.5\textwidth}
            \centering
            \includegraphics[height=1.2in]{Bilder/sample.png}
            \caption{Sample1}
        \end{subfigure}%
        ~ 
        \begin{subfigure}[t]{0.5\textwidth}
            \centering
            \includegraphics[height=1.2in]{Bilder/sample.png}
            \caption{sample2}
        \end{subfigure}
        \caption{Caption place holder}
    \end{figure}
    

    My Output is something like this.

    enter image description here

    This is neither desired nor same as by the suggested Solutions. Sample of suggested solution is as below. How to fix it?

    enter image description here

  • mokarakaya
    mokarakaya over 7 years
    should remember to import subfigure at the top of the file. \usepackage{subfigure}
  • Marses
    Marses over 4 years
    What are the percent signs for? Don't they just start comments?
  • Hamlet
    Hamlet over 4 years
    After the % character there is a newline character too. The newline characters are not ignored by LaTeX (they work like blank characters). A trick to avoid all the side effects that may cause is to "hide" that newline character into a comment, so that LaTeX really ignores it. With this trick, LaTeX sees the line with the comment and the next one as a single line with no blanks in between. Another essential part of the trick is that there must be no blank character before the comment (i.e. between } and %), lest that character will introduce the same side effects as the newline character.