Edit: Having seen the MWE, the problem is that you've put an empty line between your figures. LaTeX interprets this as a line break and then breaks the line.
Get rid of the empty line before your second picture and it works.
Here's code that works:
\documentclass{article}
\usepackage{tikz}
\usepackage{subfigure}
\usetikzlibrary{backgrounds,automata}
\begin{document}
\begin{figure}
\centering
\subfigure[Before]
{
\begin{tikzpicture}[show background rectangle, scale=.5]
\draw[rounded corners=5pt] (0,0) rectangle (6,8);
\draw[rounded corners=5pt] (1,2) rectangle (5,6);
\draw [dashed] (3,2) to[line to] (3,6);
\node[state] (a) at (3,7) {$a$};
\node[state] (b_x) at (2,5) {$b_x$};
\node[state] (b_y) at (4,5) {$b_y$};
\node[state] (c_x) at (2,3) {$c_x$};
\node[state] (c_y) at (4,3) {$c_y$};
\node[state] (d) at (3,1) {$d$};
\draw (1.25,5.75) node {$x$};
\draw (3.25,5.75) node {$y$};
\draw (0.25,7.75) node {$z$};
\end{tikzpicture}
}
% The only difference is here, where I have commented out an empty line.
\subfigure[After]
{
\begin{tikzpicture}[show background rectangle, scale = 0.5]
\draw[rounded corners=5pt] (0,0) rectangle (4,8);
\draw [dashed] (2,0) to[line to] (2,8);
\node[state] (a_x) at (1,7) {$a_x$};
\node[state] (a_y) at (3,7) {$a_y$};
\node[state] (b_x) at (1,5) {$b_x$};
\node[state] (b_y) at (3,5) {$b_y$};
\node[state] (c_x) at (1,3) {$c_x$};
\node[state] (c_y) at (3,3) {$c_y$};
\node[state] (d_x) at (1,1) {$d_x$};
\node[state] (d_y) at (3,1) {$d_y$};
\draw (0.25,7.75) node {$x$};
\draw (2.25,7.75) node {$y$};
\end{tikzpicture}
}
\caption{An example of the procedure}
\end{figure}
\end{document}
Old answer for posterity:
Without an MWE it's difficult to know exactly what the issue is. Try making the tikz pictures smaller to see if they then fit on a line. That is, make your tikz figures start: \begin{tikzpicture}[scale=0.5]
If they fit on one line once you've done this, it's then a matter of finding the largest scale you can give them and have them fit on a line. If this isn't the problem, the you'll need to give more detail to your question.
You're doing contradictory requests: you're allowing .2\linewidth
(about 69pt) for the subfigures, while you want them 4cm wide (about 114pt).
Look at the following example (I've used \test
instead of your \input
just for showing the results with the demo
option to graphicx
)
\documentclass{report}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\usepackage{tikz,pgfplots}
\newcommand{\test}{\includegraphics[width=\figurewidth,height=\figureheight]{x}}
\newlength\figureheight
\newlength\figurewidth
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.3\linewidth}
\centering
\setlength\figureheight{\linewidth}
\setlength\figurewidth{\linewidth}
\test \caption{Fig 1}
\end{subfigure}%
\hspace{1cm}%
\begin{subfigure}{.3\linewidth}
\centering
\setlength\figureheight{\linewidth}
\setlength\figurewidth{\linewidth}
\test \caption{Fig 2}
\end{subfigure}\\
\vspace{1cm}
\begin{subfigure}{4cm}
\centering
\setlength\figureheight{4cm}
\setlength\figurewidth{4cm}
\test \caption{Fig 3}
\end{subfigure}
\begin{subfigure}{4cm}
\centering
\setlength\figureheight{4cm}
\setlength\figurewidth{4cm}
\test \caption{Fig 4}
\end{subfigure}
\end{figure}
\end{document}
In the first row the squares fill all the space available (\linewidth
refers to the current linewidth, inside a subcaption
environment it's what you reserved to it) and they are separated by a 1 cm space (notice the %
comments to mask off the end of lines). In the second row the squares are 4cm wide, separated by a normal interword space.
You don't need to specify (a)
and so on in the captions, as they are provided automatically.
Best Answer
The
subfigure
environment has a mandatory argument specifying the width:I used
.5\linewidth
for each subfigure so each one will occupy half the available horizontal space and the two will appear side-by-side; of course, you can adjust those settings according to your needs. I also used\centering
to center the objects, since thecenter
environment adds (usually unnecessary) vertical spacing inside a float.