I was trying to position images as shown in the figure in LaTeX, need help.
Position images as a grid in a page
graphicspositioning
Related Solutions
This works for me:
\documentclass{article}
\usepackage{amsmath}
\newcounter{eqn}
\renewcommand*{\theeqn}{\alph{eqn})}
\newcommand{\num}{\refstepcounter{eqn}\text{\theeqn}\;}
\makeatletter
\newcommand{\putindeepbox}[2][0.7\baselineskip]{{%
\setbox0=\hbox{#2}%
\setbox0=\vbox{\noindent\hsize=\wd0\unhbox0}
\@tempdima=\dp0
\advance\@tempdima by \ht0
\advance\@tempdima by -#1\relax
\dp0=\@tempdima
\ht0=#1\relax
\box0
}}
\makeatother
\usepackage[demo]{graphicx}
% \setlength{\tabcolsep}{0pt}
\begin{document}
\begin{tabular}{cc}
\num\putindeepbox[7pt]{\includegraphics{whatever.jpg}}
& \num\putindeepbox[7pt]{\includegraphics{whatever.jpg}} \\
\num\putindeepbox[7pt]{\includegraphics{whatever.jpg}}
& \num\putindeepbox[7pt]{\includegraphics{whatever.jpg}} \\
\end{tabular}
\end{document}
(Edited to include pseudo-captions; the macro \putindeepbox
takes something and puts it into a box of height equal to 0.7\baselineskip
by default (i.e., the height of a \strut
) and deep enough to accomodate for the given material. Somehow in tabular
\baselineskip
gets reset to zero, so I've hardcoded the height manually. Not very elegant, but works - feel free to improve it;). Notice also some dirty tricks with boxes - hopefully someone will find a cleaner way to do it. I hope that this is what you wanted, and that it is not too late... See also comments below to make spacing better.)
The spacing is not perfect; you can manipulate the horizontal spacing with tabcolsep
, AFAIK there is no such parameter for vertical spacing in tabular.
Your issue with placement here seem to resolve when using the following:
Don't use a float. Instead, use the
float
package's[H]
float specifier to set the float inside aminipage
. This will give you preference over the (non-)float placement.Break the float manually at the desired location.
Use
\ContinuedFloat
from thecaption
package to retain the existing\caption
number.
\documentclass{article}
\usepackage{lipsum,graphicx,float}
\usepackage{subfig,caption}
\begin{document}
\lipsum[1-2]
\begin{figure}[H]
\centering
\setkeys{Gin}{width=2in,height=2cm,keepaspectratio}%
\subfloat[Original image]{\includegraphics{example-image}} \\
\subfloat[Layer-1]{\includegraphics{example-image-a}}
\subfloat[]{\includegraphics{example-image-b}}
\subfloat[]{\includegraphics{example-image-c}} \\
\subfloat[]{\includegraphics{example-image-a}}%%Layer-2
\subfloat[]{\includegraphics{example-image-b}}
\subfloat[]{\includegraphics{example-image-c}}
\subfloat[]{\includegraphics{example-image-a}}
\caption{images}
\end{figure}
\begin{figure}[H]
\ContinuedFloat\centering
\setkeys{Gin}{width=2in,height=2cm,keepaspectratio}%
\subfloat[]{\includegraphics{example-image-b}}%%Layer-3
\subfloat[]{\includegraphics{example-image-c}}
\subfloat[]{\includegraphics{example-image-a}}
\subfloat[]{\includegraphics{example-image-b}}\\
\subfloat[]{\includegraphics{example-image-c}}%%Layer-4
\subfloat[]{\includegraphics{example-image-a}}
\subfloat[]{\includegraphics{example-image-b}}
\subfloat[]{\includegraphics{example-image-c}}\\
\subfloat[]{\includegraphics{example-image-a}}%%Layer-5
\subfloat[]{\includegraphics{example-image-b}}
\subfloat[]{\includegraphics{example-image-c}}
\subfloat[]{\includegraphics{example-image-a}}
\caption{images}
\end{figure}
\end{document}
Placing the images using [H]
removes the issue of the last page float being set vertically centred, since the float is set like regular text, which will end up at the top of the page.
Best Answer
You can make use of the
subcaption
package and arrange the images using atabluar
. The following may be a starting point. It is not exactly semantically correct though, because from your example it seems that both, Image and Residual, should belong to the same subfigure.