Graphics, Figures & TablesMultiple subfigures not appearing on the same line

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Lumy
Posts: 24
Joined: Tue Jan 06, 2009 2:41 pm

Multiple subfigures not appearing on the same line

Post by Lumy »

The subfigures do not appear on the same line. The figures must be the same dimension.

Thank you for your help!

The code is :

Code: Select all

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{amsmath,amsthm,amsfonts,amssymb,latexsym}
\usepackage{fancyhdr,graphicx}
%Include other standard packages if you need them.
%We are using MikTex 2.4 as LaTex typesetting system.

\newtheorem{Theorem}{Theorem}
\newtheorem{Proposition}[Theorem]{Proposition}
\newtheorem{Lemma}[Theorem]{Lemma}
\newtheorem{Remark}[Theorem]{Remark}
\newtheorem{Claim}[Theorem]{Claim}
\newtheorem{Example}[Theorem]{Example}
\newtheorem{Definition}[Theorem]{Definition}
%Define other environments if you need them.

\usepackage{array}
\setlength{\textheight}{235mm} \setlength{\textwidth}{160mm}
\setlength{\headwidth}{160mm} \setlength{\evensidemargin}{0mm}
\setlength{\oddsidemargin}{0mm} \setlength{\topmargin}{0mm}
\setlength{\headheight}{25.10403pt}
\setcounter{section}{0}\setcounter{subsection}{0}
\setcounter{subsubsection}{0}\setcounter{figure}{0}
\setcounter{enumi}{0}  \setcounter{enumii}{0}
\setcounter{enumiii}{0}  \setcounter{enumiv}{0}
\setcounter{table}{0}  \setcounter{footnote}{0}
\setcounter{equation}{0}  \setcounter{mpfootnote}{0}
\setcounter{Theorem}{0}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Model image, img\_1}
\label{sfig:testa}
\end{subfigure}%
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Source image, no noise added}
\label{sfig:testb}
\end{subfigure}%
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Source image, Source image}
\label{sfig:testc}
\end{subfigure}%
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Source image, Source imageSource imageSource image}
\label{sfig:testc}
\end{subfigure}%
\\
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Registered image}
\label{test}
\end{subfigure}%
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Registered image}
\label{test}
\end{subfigure}
\begin{subfigure}{.25\linewidth}
\centering
\includegraphics[width=.8\linewidth]{blackbox.eps}
\caption{Registered image}
\label{test}
\end{subfigure}%
\caption{Sixteen subfigures}
\label{test}
\end{figure}
\end{document} 
Attachments
example subfigure.jpg
example subfigure.jpg (32.1 KiB) Viewed 6236 times

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

Multiple subfigures not appearing on the same line

Post by Johannes_B »

Package subcaption uses minipages for the subfigures. Knowing that, we know that we can set the optional argument for alignment. In this case we align all the subfigures on the top ([t]).

Code: Select all

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{amsmath,amsthm,amsfonts,amssymb,latexsym}
\usepackage{fancyhdr,graphicx}
		%Include other standard packages if you need them.
		%We are using MikTex 2.4 as LaTex typesetting system.
%JB: MiKTeX 2.4 is quite old 

\newtheorem{Theorem}{Theorem}
\newtheorem{Proposition}[Theorem]{Proposition}
\newtheorem{Lemma}[Theorem]{Lemma}
\newtheorem{Remark}[Theorem]{Remark}
\newtheorem{Claim}[Theorem]{Claim}
\newtheorem{Example}[Theorem]{Example}
\newtheorem{Definition}[Theorem]{Definition}
					    %Define other environments if you need them.

\usepackage{array}
\setlength{\textheight}{235mm} \setlength{\textwidth}{160mm}
\setlength{\headwidth}{160mm} \setlength{\evensidemargin}{0mm}
\setlength{\oddsidemargin}{0mm} \setlength{\topmargin}{0mm}
\setlength{\headheight}{25.10403pt}
%JB: better use package geometry for the layout
\setcounter{section}{0}\setcounter{subsection}{0}
\setcounter{subsubsection}{0}\setcounter{figure}{0}
\setcounter{enumi}{0}  \setcounter{enumii}{0}
\setcounter{enumiii}{0}  \setcounter{enumiv}{0}
\setcounter{table}{0}  \setcounter{footnote}{0}
\setcounter{equation}{0}  \setcounter{mpfootnote}{0}
\setcounter{Theorem}{0}
\usepackage{subcaption}
\usepackage{showframe}%show the layout of the page
\newcommand{\blackbox}{\rule{.8\linewidth}{.8\linewidth}}
\begin{document}
\begin{figure}
	\centering
	\captionsetup[subfigure]{margin=3pt}%JB: Make it less sticky
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Model image, img\_1}
		\label{sfig:testa}
	\end{subfigure}%
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Source image, no noise added}
		\label{sfig:testb}
	\end{subfigure}%
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Source image, Source image}
		\label{sfig:testc}
	\end{subfigure}%
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Source image, Source image Source image Source image}
		\label{sfig:testc}
	\end{subfigure}%
	\\
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Registered image}
		\label{test}
	\end{subfigure}%
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Registered image}
		\label{test}
	\end{subfigure}
	\begin{subfigure}[t]{.25\linewidth}
		\centering
		\blackbox
		\caption{Registered image}
		\label{test}
	\end{subfigure}%
	\caption{Sixteen subfigures}
	\label{test}
\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.
Post Reply