# Leaving no space between subfigures using package subcaption

I want to draw a figure consisting of multiple subfigures. For this, I am using the subcaption package, since the LaTeX Wikibook suggests here that both subfigure and subfig are deprecated.

The subfigures have rectangular borders, and I want no space at all in between subfigures. This should, in theory, be possible by leaving no space in between subfigure environments and inserting graphics which are exactly as wide as the subfigure environments' width. However, there remain this little horizontal gaps in between the subfigures that make everything look awful. I could play around using negative \vspace{}, but I'm looking for a "clean" solution. Is there any way to arrange subfigures to be really beside one another, with no gap in between?

Here is an example of the kind of code I am using in my document:

\documentclass[a4paper]{article}

\usepackage{tikz}
\usepackage{subcaption}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}

• Don't believe everything a Wiki says ;-) subfig is not deprecated (subfigure is indeed obsolete, though). Jul 22 '13 at 17:50

You have spurious spaces at the end of every subfigure. Insert a % and the spaces are removed. As reference, see What is the use of percent signs (%) at the end of lines? Here's a complete MWE:

\documentclass{article}

\usepackage{tikz,subcaption}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}% <-------------- Added %
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}% <-------------- Added %
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}% <-------------- Added %
\begin{subfigure}{72pt}
\begin{tikzpicture}[x=72pt]
\draw[blue] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}

• I'm confused. I couldn't find any spaces at the end of my lines, and still adding the % helped me fix my problem; my output looks like I wanted... I don't understand which spaces I am omitting, since there were none after the curly braces. Jul 22 '13 at 17:45
• @MHaaZ: If you leave a line-break, that is similar to a space (commonly referred to as a spurious space). Adding % acts to concatenate the two lines, almost like writing \end{subfigure}\begin{subfigure}. Be sure to leave no spaces though. For example, the following will still insert a space \end{subfigure} %, since it translates to \end{subfigure} \begin{subfigure}. Try it... Jul 22 '13 at 17:50
• Thanks a lot for clarifying. So every time I insert a linebreak into my source file, an extra space gets added into the output? That seems weird... what am I missing? (feel free to tell me to RTFM, as long as you reference said manual :)) Jul 22 '13 at 17:52
• Just realized you included a reference at the bottom of your answer. I just saw your code and didn't keep on reading... might wanna push that link before the code so other impatient people don't miss it :) Jul 22 '13 at 17:53
• @MHaaZ: Done. And yes, but multiple spaces are gobbled into a single one. In a similar sense, you can leave 1 line or 100 between paragraphs. Jul 22 '13 at 17:55