Put figures into longtable

floatslongtable

Below is my code where I'm trying to put figures into longtable. I'm wondering how can I decrease the spaces between figures (columns) and how can I stretch the figures to both margins?

\documentclass[letter]{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{ltcaption}
\usepackage{duckuments}% for variety
\usepackage[showframe]{geometry}

\begin{document}

\noindent\rule{\textwidth}{20\baselineskip}

\renewcommand{\LTcaptype}{figure}%
\begin{longtable}{@{}ccc@{}}
  \caption{Empirical Regularities During Currency Crises \label{fig: cc}}
\endhead
\includegraphics[width=.31\textwidth]{example-image-duck} & 
\includegraphics[width=.31\textwidth]{example-image-duck} & 
\includegraphics[width=.31\textwidth]{example-image-duck}\\
%
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} \\
%
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} \\
%
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} \\
%
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} &
\includegraphics[width=.3\textwidth]{example-image-duck} \\
\end{longtable}

\end{document}

Best Answer

I suggest defining your own environment so as not to litter the document with instructions that should be local.

\documentclass{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{ltcaption}
\usepackage{duckuments}% for variety

\usepackage[pass,showframe]{geometry}

\newenvironment{longfigure}[2][]{%
  % #1 (optional) is arbitrary code to be executed before the longtable
  % #2 is the column specification
  \renewcommand{\LTcaptype}{figure}%
  \setlength{\LTleft}{0pt}%
  #1%
  \begin{longtable}{#2}
}{\end{longtable}\addtocounter{figure}{-1}}

\begin{document}

\noindent\rule{6pt}{20\baselineskip}

\begin{longfigure}[\setlength{\tabcolsep}{0.01\textwidth}]{@{}ccc@{}}
  \caption{Empirical Regularities During Currency Crises \label{fig:cc}}
\endfirsthead
  \caption*{Empirical Regularities During Currency Crises (continued)}
\endhead
\includegraphics[width=0.32\textwidth]{example-image-duck} & 
\includegraphics[width=0.32\textwidth]{example-image-duck} & 
\includegraphics[width=0.32\textwidth]{example-image-duck}\\
%
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} \\
%
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} \\
%
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} \\
%
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} &
\includegraphics[width=0.32\textwidth]{example-image-duck} \\
\end{longfigure}

\end{document}

The magic factor 0.01 for the \tabcolsep comes from the fact that we have three columns, each 32% of the \textwidth, so we need to divide the remaining space in four parts.

enter image description here

A modification for using subfigure:

\documentclass{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{ltcaption}
\usepackage{duckuments}% for variety
\usepackage{subcaption}

\usepackage[pass,showframe]{geometry}

\newenvironment{longfigure}[2][]{%
  % #1 (optional) is arbitrary code to be executed before the longtable
  % #2 is the column specification
  \renewcommand{\LTcaptype}{figure}%
  \expandafter\def\csname @captype\endcsname{figure}%
  \setcounter{subfigure}{0}%
  \setlength{\LTleft}{0pt}%
  #1%
  \begin{longtable}{#2}
}{\end{longtable}\addtocounter{figure}{-1}}

\begin{document}

\noindent\rule{6pt}{20\baselineskip}

\begin{longfigure}[\setlength{\tabcolsep}{0.01\textwidth}]{@{}ccc@{}}
  \caption{Empirical Regularities During Currency Crises \label{fig:cc}}
\endfirsthead
  \caption*{Empirical Regularities During Currency Crises (continued)}
\endhead
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\end{longfigure}

\end{document}

enter image description here

Since barbara beeton commented about the awkward spacing, here's a workaround.

\documentclass{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{ltcaption}
\usepackage{duckuments}% for variety
\usepackage{subcaption}

\usepackage[pass,showframe]{geometry}

\newenvironment{longfigure}[2][]{%
  % #1 (optional) is arbitrary code to be executed before the longtable
  % #2 is the column specification
  \renewcommand{\LTcaptype}{figure}%
  \expandafter\def\csname @captype\endcsname{figure}%
  \setcounter{subfigure}{0}%
  \setlength{\LTleft}{0pt}%
  #1%
  \begin{longtable}{#2}
}{\end{longtable}\addtocounter{figure}{-1}}

\begin{document}

\noindent\rule{6pt}{20\baselineskip}

\begin{longfigure}[{%
  \AtEndEnvironment{subfigure}{\vspace{4pt}}%
  \captionsetup[subfigure]{aboveskip=1pt}%
  \setlength{\tabcolsep}{0.01\textwidth}%
}]{@{}ccc@{}}
  \caption{Empirical Regularities During Currency Crises \label{fig:cc}}
\endfirsthead
  \caption*{Empirical Regularities During Currency Crises (continued)}
\endhead
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} &
\begin{subfigure}{0.32\textwidth}
\includegraphics[width=\textwidth]{example-image-duck}
\caption{A subfigure}
\end{subfigure} \\
%
\end{longfigure}

\end{document}

enter image description here

Related Question