Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to get my subfigures on the same line.

Right now I successfully use the subfigure and TikZ packages to have a Fig. 1 (a) and Fig 1. (b).

However, no matter what I have tried they are stacked one above the other. I would like the two subfigures to be side by side.

\documentclass{article} 
\usepackage{subfigure,tikz}
\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}
}

\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}
share|improve this question
1  
You need to make sure that your tikz figures are small enough that they both fit on one line. try using the scale argument to see whether shrinking the figures makes them fit. –  Seamus Mar 10 '11 at 14:18
2  
@zucchininja: you need only to remove the blank lines before \subfigure[After] –  Alain Matthes Mar 10 '11 at 16:22
2  
I formatted your example as code, which can be done by adding four spaces at the start of each line, or simply selecting the code chunk and pressing the 10101 button in the editor. Note that it would be helpful if you posted a full MWE, including your preamble (so starting from \documentclass). At the moment, your code is not compilable because the definition of state is missing. Also note that the subfigure package is deprecated, and subfig should be used instead (see here: tex.stackexchange.com/questions/1966/…) –  Jake Mar 10 '11 at 16:24
    
@Jake: I edited the code in the same time to make exactly that you made. Is it a problem ? you need to add \usetikzlibrary{backgrounds,automata} –  Alain Matthes Mar 10 '11 at 16:29
1  
@zucchininja please upload a minimal working example. That is, with documentclass and calling the relevant packages needed. We don't have time to guess what tikz libraries this code might need... –  Seamus Mar 10 '11 at 16:32

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
Thanks for the comments, but I tried to make the scale as tiny as possible, and I even but a background rectangle to see what the bounding areas actually are. So I tried to make them really small, but it doesn't help. I will upload the code I used. –  klyngbaek Mar 10 '11 at 16:10

An example :

\documentclass{scrartcl} 
\usepackage{tkz-euclide,subfigure}
\usetkzobj{all}    
\begin{document}    
\begin{figure}[!h]
\centering
\subfigure[angle:\hbox to 2cm{\dotfill}]{
 \begin{tikzpicture}
    \draw  ( 2,3)+(158:4cm) -- ( 2,3) -- +(31:4cm);    
\tkzOriProtractor[scale=0.7, shift = {(2,3)}, rotate = -22]
\end{tikzpicture}}
\hfill
\subfigure[angle:\hbox to 2cm{\dotfill}]{
 \begin{tikzpicture}
 \def\ang{53}
 \draw  ( 2,3)+(180-\ang:4cm) -- ( 2,3) -- +(31:4cm);
\tkzOriProtractor[shift = {(2,3)}, scale=0.7, rotate = 31]
\end{tikzpicture}}
\end{figure}
\end{document}

enter image description here

share|improve this answer
4  
since the subfigure package is considered obsolete, I would use in your nice example one of the packages subfig or subcaption instead. –  Gonzalo Medina Mar 10 '11 at 16:30
    
@Gonzalo Medina: It was an example for my documentation and I don't know the subfigure package was considered obsolete. Now With Jake and you, I notice that subfig or subcaption are perhaps better, but I like to make a try and to test all the possibilities. –  Alain Matthes Mar 10 '11 at 16:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.