Graphics, Figures & TablesArrangement of three Sub-figures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
m0vtf
Posts: 5
Joined: Thu Jun 06, 2013 8:37 pm

Arrangement of three Sub-figures

Post by m0vtf »

Hi,

I am attempting to place three images into a subplot, with one centrally placed on the page above the other two. When i run the attached code it places everything left justified. I have checked by using \fbox whether the images have empty white space but i cannot see any. The \qquad command needs to be used so many times to separate the two horizontal images as they were being placed overlapping.

Code: Select all

\usepackage{graphics}
\usepackage{makeidx}
\usepackage{nomencl}
\usepackage{graphicx}
\usepackage{url}
\usepackage{notoccite}
\usepackage{subcaption}

\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth} 
    \centering
    \includegraphics[height=3in]{C:/Users/NuclearPhysics/Documents/ThesisDiagrams/244_allcones_comp3.png}
    \caption{}
    \label{fig:244keV_image_Aldermaston}
  \end{subfigure}

  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[height=2.5in]{C:/Users/NuclearPhysics/Documents/ThesisDiagrams/244_allcones_comp3_fitX.png}
    \caption{}
    \label{fig:244keV_image_Xfit_Aldermaston}
  \end{subfigure}% 
  \qquad \qquad \qquad \qquad \qquad
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[height=2.5in]{C:/Users/NuclearPhysics/Documents/ThesisDiagrams/244_allcones_comp3_fitY.png}
    \caption{}
    \label{fig:244keV_image_Yfit_Aldermaston}
  \end{subfigure}
  \caption{The image produced by gating on 244keV is shown in (a), the background is much reduced compared to \ref{fig:122keV_image_Aldermaston} as the scattered gamma rays are becoming more forward focused as shown in the Klien Nishina distribution. The FWHM of the image is ~19mm.  (b) and (c) are cross sections through the X and Y axis respectively, showing the Laplacian fit to the data used to create the image.}
\end{figure}
I have messed around with \centering above the first sub-figure but this right justifies the images, removing it left justifies them. The horizontal images are slightly wider than the text column, so using \qquad so many times has moved the right hand image almost to the page edge as shown in the attached image.
Screenshot.png
Screenshot.png (74.69 KiB) Viewed 33212 times
Is there a way of centering the top image and then placing the two horizontal images such that they are aligned centrally as well?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Arrangement of three Sub-figures

Post by Johannes_B »

Hi, please have a look at how to make a minimal working example

You need to place the \centering command at the top of the environment. I replaced the graphics with the \rule command because I don't have the actual files.

Code: Select all

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
  \begin{figure}
    \centering
    \begin{subfigure}[b]{0.5\textwidth} 
      \centering
      \rule{2cm}{2cm}
      \caption{}
      \label{fig:244keV_image_Aldermaston}
    \end{subfigure}\\
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \rule{2cm}{2cm}
      \caption{}
      \label{fig:244keV_image_Xfit_Aldermaston}
    \end{subfigure}% 
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \rule{2cm}{2cm}
      \caption{}
      \label{fig:244keV_image_Yfit_Aldermaston}
    \end{subfigure}
    \caption{ The image produced by gating on 244keV is shown in (a), the background is much reduced compared to \ref{fig:122keV_image_Aldermaston} as the scattered gamma rays are becoming more forward focused as shown in the Klien Nishina distribution. The FWHM of the image is ~19mm.  (b) and (c) are cross sections through the X and Y axis respectively, showing the Laplacian fit to the data used to create the image.}
  \end{figure}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
m0vtf
Posts: 5
Joined: Thu Jun 06, 2013 8:37 pm

Arrangement of three Sub-figures

Post by m0vtf »

That only moves the images to the right of center, and then the two horizontal images are overlapped and cannot be separated using \qquad as the right hand one is moved off the edge of the page.

Sorry about the minimal example, new to LaTeX.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Arrangement of three Sub-figures

Post by Johannes_B »

Did you take a look at my example? I removed the \quad commands because they are not useful here, at least I don't see why they could be.

Please adapt my example to your code (make a backup first, just to be sure) and see if it works.


EDIT: I just realised, you want the top one and the first one of line to to be equally aligned? Then, wouldn't it be better to completely flushleft the whole bunch?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
m0vtf
Posts: 5
Joined: Thu Jun 06, 2013 8:37 pm

Re: Arrangement of three Sub-figures

Post by m0vtf »

Thanks for replying.

I looked at it and modified the example, please see attached image.

The middle figure is fine however the bottom two are overlapping as previously described. The rule images when I run those are placed in the correct location however.
Attachments
screenshot.png
screenshot.png (66.29 KiB) Viewed 33196 times
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Arrangement of three Sub-figures

Post by Johannes_B »

I took another look at your example using example images from the mwe package. I guess giving the pictures an explicit height isn't the best idea. Try setting the width as in my example. But I don't know your actual pictures.

Code: Select all

\documentclass[12pt]{article}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
  \begin{subfigure}[b]{0.5\textwidth} 
    %\centering
    \includegraphics[width=2.5in]{example-image}
    \caption{}
    \label{fig:244keV_image_Aldermaston}
  \end{subfigure}\\
  \begin{subfigure}[b]{0.3\textwidth}
 %  \centering
    \includegraphics[width=2.5in]{example-image}
    \caption{}
    \label{fig:244keV_image_Xfit_Aldermaston}
  \end{subfigure}% 
  \qquad \qquad \qquad \qquad \qquad
  \begin{subfigure}[b]{0.3\textwidth}
 %  \centering
    \includegraphics[width=2.5in]{example-image}
    \caption{}
    \label{fig:244keV_image_Yfit_Aldermaston}
  \end{subfigure}
  \caption{figure caption}
\end{figure}
\end{document}
But be careful with the width of the pictures and the width of the subfigure, right now this is messy, even if it looks okk on writelatex (try it out, it's great).
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
m0vtf
Posts: 5
Joined: Thu Jun 06, 2013 8:37 pm

Arrangement of three Sub-figures

Post by m0vtf »

Thanks for that.

Without using the \qquad commands the images just barely overlap once the centering command was commented out. Is there a way to move the first image to the left, similar to \qquad, would only need two steps in each direction to bring the images apart.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Arrangement of three Sub-figures

Post by localghost »

In your arrangement the width of the figures given as option to the \includegraphics commands and the reserved width given as option to the subfigure environments don't match. You should get corresponding warnings.

Try something like this where sizes (widths) are defined in dependence of the text width and the width of the box in the subfigure environments. Click on "Open in writeLaTeX" in the head of the below code box to see the output instantly.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mwe}  % loads »blindtext« and »graphicx«
\usepackage{subcaption}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \begin{subfigure}[b]{0.45\textwidth} 
      \includegraphics[width=\linewidth]{example-image-a}
      \caption{First}
      \label{subfig-1:dummy}
    \end{subfigure}\\[2ex]
    \begin{subfigure}[b]{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image-b}
      \caption{Second}
      \label{subfig-2:dummy}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image-c}
      \caption{Third}
      \label{subfig-3:dummy}
    \end{subfigure}
    \caption{Dummy figure}
    \label{fig:dummy}
  \end{figure}
\end{document}

Best regards and welcome to the board
Thorsten
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Arrangement of three Sub-figures

Post by Johannes_B »

As i said before, you have to take care of the width option. Right now, 2.5in is bigger than 30% of textwidth.

Code: Select all

\documentclass[12pt]{article}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
  \begin{subfigure}[b]{0.45\textwidth} 
    \includegraphics[width=\textwidth]{example-image}
    \caption{}
    \label{fig:244keV_image_Aldermaston}
  \end{subfigure}\\
  \fbox{
  \begin{subfigure}[b]{0.45\textwidth}
     \includegraphics[width=\textwidth]{example-image}
    \caption{}
    \label{fig:244keV_image_Xfit_Aldermaston}
  \end{subfigure}% 
  }%
  \hfill
  \fbox{
  \begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{example-image}
    \caption{}
    \label{fig:244keV_image_Yfit_Aldermaston}
  \end{subfigure}
  }
  \caption{figure caption}
\end{figure}
\end{document}
Subfigure is realised with a minipage, so the textwidth is now the width of the subfigure/minipage <- not exactly correct. linewidth is the width of he current line.


EDIT: Thorsten is right, linewidth would be more appropriate.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
m0vtf
Posts: 5
Joined: Thu Jun 06, 2013 8:37 pm

Re: Arrangement of three Sub-figures

Post by m0vtf »

Thanks for your help guys.

Using linewidth worked and i have just played with the sizes to optimise the image as much as possible for reading after conversion to pdf. Now to put the hundred or so images in with the same format......
Post Reply