Here's a minimal example reproducing your problem:
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[31]{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}
\begin{subfigure}[227]{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-b}
\caption{Channel 227}\label{fig:227}
\end{subfigure}
\end{figure}
\end{document}

The error is in the wrong syntax used: the optional argument to \begin{subfigure}
should be a single character among b
, c
or t
.
Fix: remove the wrong bits
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-b}
\caption{Channel 227}\label{fig:227}
\end{subfigure}
\end{figure}
\end{document}

What happens?
The code for \begin{subfigure}
looks whether an optional argument is supplied, otherwise assumes it is b
; then it does code like
\if<optional argument>b%
<code when test returns true>%
\else
<code when test returns false>%
\fi
In the 227
case, the text becomes
\if227b
<code when test returns true>%
\else
<code when test returns false>%
\fi
and the test returns true because \if
compares the next two unexpandable tokens, in this case 2
and 2
. By rule, the <true code>
starts just after the test and ends at \else
(or \fi
if no \else
comes along), so in this case it also contains 7b
.
How to get five images per row with no space?
You should remove the space between two subfigures, generated by the end-of-line after \end{subfigure}
.
You can exploit the fact that TeX removes spaces after control sequences:
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\newcommand{\subfiguresep}{\hspace{0pt}}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{0.2\textwidth}
\includegraphics[width = \textwidth]{example-image-b}
\caption{Channel 227}\label{fig:227}
\end{subfigure}\subfiguresep
\end{figure}
\end{document}

The \hspace{0pt}
allows for a line break, adding no space. If you prefer the last row flush left, use \raggedright
instead of \centering
.
If you want some space between the subfigures, you can do
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\newcommand{\subfiguresep}{\hspace{2pt}}
\captionsetup[subfigure]{font=footnotesize}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-a}
\caption{Channel 31}\label{fig:31}
\end{subfigure}\subfiguresep
\begin{subfigure}{\dimexpr 0.2\textwidth-8pt}
\includegraphics[width = \textwidth]{example-image-b}
\caption{Channel 227}\label{fig:227}
\end{subfigure}\subfiguresep
\end{figure}
\end{document}
Note I had to reduce the font size for the subcaption, otherwise it would exceed the image width.
