[Tex/LaTex] 2×2 subfigures with tikz graphs

floatssubcaptionsubfloatstikz-pgf

I saw that this has been asked before, but none of the solutions appear to work in my document. I am trying to set an 2×2 grid of sub figures, each filled with a tikz graph. However, no matter how much i adjust the textwidth or the scale, they are always displayed one below the other.

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[Ex2]%
{{\small Ex1}}    
\end{subfigure}

\quad

\begin{subfigure}[b]{0.4\textwidth}  
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex2}}    
\end{subfigure}

\bigskip 

\begin{subfigure}[b]{0.4\textwidth}   
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex3}}
\end{subfigure}

\quad

\begin{subfigure}[b]{0.4\textwidth}   
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex4}}    
\end{subfigure}
\caption[ Ex ]
{\small A small Ex} 
\end{figure}
\end{document}

Best Answer

The subcaption package interprets spaces between subfigure environments within the figure to be new rows. Removing the space between these environments (and the unnecessary \quad and bigskip) yields the desired 2x2

two rows figures

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[Ex2]%
{{\small Ex1}}    
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}  
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex2}}    
\end{subfigure}

\begin{subfigure}[b]{0.4\textwidth}   
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex3}}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}   
\centering 
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex4}}    
\end{subfigure}
\caption[ Ex ]
{\small A small Ex} 
\end{figure}
\end{document}