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 have 4 things drawn with tikz. It's working fine but now I want to layout them in a grid 2x2, each one with its own caption.

EDIT: I have rewritten my question since It was not clear. Below code is what I want to a reduced version of what I want to draw but I want it to appear in a 2x2 layout. Currently I get everything in a column. Taking too much space

\begin{figure}
\centering
\subfloat[Start 1]{
    \label{fig:chap3_input_image}
    \begin{tikzpicture}[scale=2.0]
        \tikzstyle{every node}=[draw, shape=circle];
        \path (0:0cm) node[fill=black!40] (v0){$v_0$};
        \path (20:0.8cm) node (v1){$v_1$};
        \path (340:0.9cm) node (v8){$v_8$};
    \end{tikzpicture}
}
\hfill
\caption[Start]{Initial state}
\subfloat[State 2]{
    \label{fig:chap3_input_image2}
    \begin{tikzpicture}[scale=2.0]
        \tikzstyle{every node}=[draw, shape=circle, fill=black!20];
        \path (0:0cm) node[fill=black!40] (v0){$v_0$};
        \path (20:0.8cm) node (v1){$v_1$};
        \path (340:0.9cm) node (v8){$v_8$};
    \end{tikzpicture}
}
\caption[Step2]{State 2}
\subfloat[State 3]{
    \label{fig:chap3_input_image3}
    \begin{tikzpicture}[scale=2]
        \tikzstyle{every node}=[draw, shape=circle];
        \path (0:0cm) node[fill=black!30] (v0){$v_0$};
        \path (20:0.8cm) node (v1){$v_1$};
        \path (340:0.9cm) node (v8){$v_8$};
    \end{tikzpicture}
}
\hfill
\caption[Third step]{Third step of algorithm}
\subfloat[Step 4]{
    \label{fig:chap3_input_image4}
    \begin{tikzpicture}[scale=2]
        \tikzstyle{every node}=[draw, shape=circle];
        \path (0:0cm) node[fill=black!30] (v0){$v_0$};
        \path (20:0.8cm) node (v1){$v_1$};
        \path (60:1.0cm) node (v2){$v_2$};

        \path (340:0.9cm) node (v8){$v_8$};
    \end{tikzpicture}
}
\caption[Algorithm X]{Flow of algorithm X}
\label{fig:AlgorithFlow}
\end{figure}

Thanks in advance

share|improve this question
    
as seen in my example the \caption macro is only used once for all images. The sub captions have to be inside the \subfloat command –  Herbert Jan 19 '11 at 15:43

2 Answers 2

up vote 8 down vote accepted

then do not put them in a row!

\documentclass{article}
\usepackage{subfig,tikz}

\begin{document}

\begin{figure}
\centering
\subfloat[Input Image]{\label{fig:inputimage}
\begin{tikzpicture}
  \draw (0,0)--(90:1cm) arc (90:360:1cm) arc (0:30:1cm)--cycle;
  \draw (60:5pt)-- +(30:1cm) arc (30:90:1cm)--cycle;
  \draw (2.5,0) +(0:1cm)-- +(72:1cm)-- +(144:1cm)-- +(216:1cm)--
              +(288:1cm)--cycle;
\end{tikzpicture}}
\hfill
\subfloat[Sobel Edge detector]{\label{fig:sobel}
\begin{tikzpicture}
  \draw (0,0)--(90:1cm) arc (90:360:1cm) arc (0:30:1cm)--cycle;
  \draw (60:5pt)-- +(30:1cm) arc (30:90:1cm)--cycle;
  \draw (2.5,0) +(0:1cm)-- +(72:1cm)-- +(144:1cm)-- +(216:1cm)--
              +(288:1cm)--cycle;
\end{tikzpicture}}

\subfloat[Canny Edge detector]{\label{fig:canny}
\begin{tikzpicture}
  \draw (0,0)--(90:1cm) arc (90:360:1cm) arc (0:30:1cm)--cycle;
  \draw (60:5pt)-- +(30:1cm) arc (30:90:1cm)--cycle;
  \draw (2.5,0) +(0:1cm)-- +(72:1cm)-- +(144:1cm)-- +(216:1cm)--
              +(288:1cm)--cycle;
\end{tikzpicture}}
\hfill
\subfloat[K means clustering]{\label{fig:chap1_kmeans}
\begin{tikzpicture}
  \draw (0,0)--(90:1cm) arc (90:360:1cm) arc (0:30:1cm)--cycle;
  \draw (60:5pt)-- +(30:1cm) arc (30:90:1cm)--cycle;
  \draw (2.5,0) +(0:1cm)-- +(72:1cm)-- +(144:1cm)-- +(216:1cm)--
              +(288:1cm)--cycle;
\end{tikzpicture}}
\caption{My caption}
\label{fig:methods}
\end{figure}

\end{document}

alt text

share|improve this answer
    
If I replace \includegraphics{...} with my \begin{tikzpicture}...\end{tikzpicture}code I still getting them in a column. Probably my question was not clear enough, I want to use tikspicture instead of images. What am I missing here? –  nacho4d Jan 19 '11 at 15:29
    
@nacho4d: that makes no difference, see edited example. Maybe that your single tikz image is wider than 0.5\textwidth then the next one will go into a new line. –  Herbert Jan 19 '11 at 15:37

Other option:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\tikzset{inner sep=0pt,outer sep=0pt}
\begin{figure}
 \centering
 \begin{tikzpicture}
  \node (A) at (0,0) {\label{fig:inputimage}\includegraphics[width=0.45\textwidth]{inputimg}};
  \node[right=of A] (B) {\label{fig:sobel}\includegraphics[width=0.45\textwidth]{sobelimg}};
  \node[below=of A] (C) {\label{fig:canny}\includegraphics[width=0.45\textwidth]{cannyimg}};
  \node[right=of C] (D) {\label{fig:chap1_kmeans}\includegraphics[width=0.45\textwidth]{kmeansimg}};
 \end{tikzpicture}
 \caption{My caption}
 \label{fig:methods}
\end{figure}
\end{document}
share|improve this answer

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.