Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to create a block of subfigures with no space between them,

result

The above is the desired result, but the way I did it feels hacky.

I used a newline forcer followed by negative vertical space

\\[-28pt]

Is there a better way to do this? (collapse the vertical space that appears by default between lines 123 and 456 in the figure?)

Source:

\begin{centering}
\begin{figure}
\begin{centering}
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{1}
    \includegraphics[width=\textwidth]{1.png}
    \label{fig1}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{2}
    \includegraphics[width=\textwidth]{2.png}
    \label{fig2}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{3}
    \includegraphics[width=\textwidth]{3.png}
    \label{fig3}
  \end{subfigure}\\[-28pt]
  \begin{subfigure}[b]{0.33\textwidth}
    \includegraphics[width=\textwidth]{4.png}
    \caption{4}
    \label{fig4}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \includegraphics[width=\textwidth]{5.png}
    \caption{5}
    \label{fig5}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \includegraphics[width=\textwidth]{6.png}
    \caption{6}
    \label{fig6}
  \end{subfigure}%
  \caption{images}\label{imagetable}
\end{centering}
\end{figure}
\end{centering}
share|improve this question
    
The centering environment doesn't exist; use only \centering at the start and definitely not enclose figure in the inexistent environment. –  egreg Jul 13 '12 at 16:33

1 Answer 1

up vote 3 down vote accepted

I tried to reproduce your document, but since I don't have the png files, I re-created the figures using TikZ.

Doing so, I noticed that your problem is probably due to two factors:

  1. The included graphics are exactly of the width of the allowable space (\textwidth)
  2. The end-of-line character after your \includegraphics is equivalent to a white space, and since the graphic left no-room for that space, a new line is created inside the sub-figure.

It is that new (blank) line the one which causes the gap between rows. So I guess your problem will go away if you put a % after each of your \includegraphics. That % will "comment out" the carriage return and then the new blank line is not required.

The following MWE shows the solution, but using TikZ instead of \includegraphics for the figures, to improve the portability of the example.

\documentclass{article}
%\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}

% Macro to create "sample" figures
\def\makefig#1#2{%  First the background color, second the number
\tikz{\fill[#1] (0,0) rectangle (\textwidth,\textwidth)%
  node[midway,black]{\textsf{\LARGE#2}};}%  <<--- This % is crucial
}

\begin{document}
\begin{figure}
\centering\lineskip=0pt
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{1}%
    \makefig{red}{1}%
    \label{fig1}%
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{2}
    \makefig{blue}{2}%
    \label{fig2}%
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \caption{3}
    \makefig{green}{3}%
    \label{fig3}%
  \end{subfigure}\\
  \begin{subfigure}[b]{0.33\textwidth}
    \makefig{cyan}{4}
    \caption{4}
    \label{fig4}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \makefig{yellow}{5}
    \caption{5}
    \label{fig5}
  \end{subfigure}%
  \begin{subfigure}[b]{0.33\textwidth}
    \makefig{magenta}{6}
    \caption{6}
    \label{fig6}
  \end{subfigure}%
  \caption{images}\label{imagetable}
\end{figure}
\end{document}

And the result is:

Output

share|improve this answer
    
Rather than the % after \includegraphics{...} I suggest to put \label{...} just after \caption{...}. After the third subfigure, put \\[-\lineskip]. –  egreg Jul 13 '12 at 16:39
    
Great answer! One of the key take away points here is he added \lineskip=0pt just after beginning the figure (adding comments alone will still leave a small space if you don't 0 the lineskip) –  bobobobo Jul 13 '12 at 17:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.