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'm trying to draw two figures next to each others using tikzpicture. It's working fine, but the caption of the sub-figures is looking weird.

I tried adding the \qquad's, but I'm still having the same problem.

Here's my code;

\documentclass{article}
\usepackage{tikz,subfigure}
\begin{document}
\begin{figure}[!hb]%
\centering
\subfigure[Caption for subfigure 1]{
\begin{tikzpicture}[every node/.style={circle,draw}]
\node{5};
\end{tikzpicture}
}
\qquad\qquad\qquad
\subfigure[Caption for subfigure 2]{
\begin{tikzpicture}[every node/.style={circle,draw}]
\node{}
        child{node{}}
        child[missing];
\end{tikzpicture}
}
\caption{}%
\label{}%
\end{figure}

\end{document}

Here's the resulting image

enter image description here

share|improve this question
    
It's a bounding box problem. Add \path (0,0) rectangle(3,3); to both tikzpictures to see the effect. So either adjust the bounding boxes within tikzpicture environments or use minipages or other artificial boxes. –  percusse Mar 18 '12 at 3:40
    
@percusse: Using \path (0,0) rectangle(3,3); solved my problem. Thank you –  Roronoa Zoro Mar 18 '12 at 3:46
    
Note that the subfigures are not centered with respect to the subcaptions. Because the quick fix starts from the origin and the nodes are also aligned towards the origin too. So give explicit coordinates to your nodes to avoid that. –  percusse Mar 18 '12 at 3:49
    
The centering can be obtained by \path (-2,0) rectangle (2,0); which also doesn't add to the picture's height. –  egreg Mar 18 '12 at 9:32
add comment

1 Answer

up vote 2 down vote accepted

It's a bounding box problem. you can add a node with [minimum width=xxxcm]

\documentclass{article}
\usepackage{tikz,subfigure}
\begin{document}
\begin{figure}[!hb]%
\centering
\subfigure[Caption for subfigure 1]{
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,draw}]
\node(a){5};
\end{scope}
\node[minimum width=3.5cm] at (a){};
\end{tikzpicture}
}
\qquad\qquad\qquad
\subfigure[Caption for subfigure 2]{
\begin{tikzpicture}

\begin{scope}[every node/.style={circle,draw}]
\node(a){}
        child{node{}}
        child[missing];

\end{scope}
  \node[minimum width=3.5cm] at (a){};      
\end{tikzpicture}
}
\caption{}%
\label{}%
\end{figure}

\end{document}

node

share|improve this answer
add comment

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.