# Simple legend box below multiple TikZ pictures

I have three subfigures in a figure, each has three TikZ pictures inside and a caption. Now I would like to add a legend for all TikZ pictures together.

I searched through other posts and tried different solutions. However I couldn't find anything to make it work. The closest one I found, was the proposed matrix from this question: TikZ picture: how to add a legend?

I used the matrix in the bottom right TikZ picture with labels without the nodes, since I don't have any symbols.

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}

\begin{figure}%
\centering
\begin{subfigure}[c]{\textwidth}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (4,4);
\end{tikzpicture}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (4,4);
\end{tikzpicture}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (4,4);
\matrix [draw,below left] at (current bounding box.south east) {
\node [label=right:R...ROBOT] {}; \\
\node [label=right:G...GOAL] {}; \\
\node [label=right:O...OBSTACLE] {}; \\
};
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}


In my case, this destroys the layout:

• Please add the complete minimal working example, from \documentclass{} to \end{document}, instead of the code snippet. – nidhin Oct 17 '19 at 8:45

Combine the three tikzpictures. Use scope if needed.

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}

\begin{figure}%
\centering
\begin{subfigure}[c]{\textwidth}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid ++(4,4);
\draw[step=1cm,gray,very thin] (5,0) grid ++(4,4);
\draw[step=1cm,gray,very thin] (10,0) grid ++(4,4);

\matrix [draw,below left] at (current bounding box.south east) {
\node [label=right:R...ROBOT] {}; \\
\node [label=right:G...GOAL] {}; \\
\node [label=right:O...OBSTACLE] {}; \\
};
\end{tikzpicture}
\subcaption{c}
\end{subfigure}
\end{figure}
\end{document}