如何以 2x2 布局放置 4 个 tikzfigures?

如何以 2x2 布局放置 4 个 tikzfigures?

我用 tikz 画了 4 幅画。它运行良好,但现在我想将它们布置在 2x2 网格中,每个网格都有自己的标题。

编辑:我重写了我的问题,因为不太清楚。下面的代码是我想要的缩小版,但我希望它出现在 2x2 布局中。目前我把所有内容都放在一列中。占用太多空间

\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}

提前致谢

答案1

那么不要把它们排成一排!

\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}

替代文本

答案2

其他选择:

\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}

相关内容