サブプロットの共通キャプション

サブプロットの共通キャプション

両方のプロットの中央に、ラベルを介して参照できる共通のキャプションを作成するにはどうすればよいでしょうか。また、サブプロットのキャプションが 1 行に収まるように (a) と (b) を削除するにはどうすればよいでしょうか。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{subfig}
\usepackage{float}

\begin{document}
\begin{figure}
\centering
\subfloat[Compability graph]
{%
\begin{tikzpicture}
    \node[shape=circle,draw=black] (A) at (0,0) {3};
    \node[shape=circle,draw=black] (B) at (0,1) {2};
    \node[shape=circle,draw=black] (C) at (0,2) {1};
    \node[shape=circle,draw=black] (D) at (2,0) {6};
    \node[shape=circle,draw=black] (E) at (2,1) {5};
    \node[shape=circle,draw=black] (F) at (2,2) {4} ;

    \path [-] (C) edge node[left] {} (D);
    \path [-] (C) edge node[left] {} (E);
    \path [-] (C) edge node[left] {} (F);
    \path [-] (B) edge node[left] {} (E);
    \path [-] (B) edge node[left] {} (D);
     \path [-] (A) edge node[left] {} (D);
\end{tikzpicture}
%
}\hfil
\subfloat[Conflict graph]
{%
\begin{tikzpicture}
    \node[shape=circle,draw=black] (A) at (0,0) {3};
    \node[shape=circle,draw=black] (B) at (0,1) {2};
    \node[shape=circle,draw=black] (C) at (0,2) {1};
    \node[shape=circle,draw=black] (D) at (2,0) {6};
    \node[shape=circle,draw=black] (E) at (2,1) {5};
    \node[shape=circle,draw=black] (F) at (2,2) {4} ;

    \path [-] (B) edge node[left] {} (F);
    \path [-] (A) edge node[left] {} (E);
     \path [-] (A) edge node[left] {} (F);
\end{tikzpicture}
%
}
\end{figure}
\end{document}

答え1

下の写真のようなものがお好みだと思います。

ここに画像の説明を入力してください

subcationあなたが意図していることをやらないようにしたいです。数字 ( (a)、 )を消すと(b)、それらを参照できなくなります。1 行の場合は、subcation上の図のように水平距離を少し広げた方がよいでしょう。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,positioning}
\usepackage{subfig}
\usepackage{float}

\begin{document}
\begin{figure}
\centering
\subfloat[Compability graph \label{fig:main-a}]
{%
\begin{tikzpicture}[
    node distance = 3mm and 22mm,
      start chain = going above,
every node/.style = {shape=circle, draw=black, 
    inner sep=1mm, on chain}
                    ]
\node   (A) {3};
\node   (B) {2};
\node   (C) {1};
%
\node   (D) [right=of A]    {6};
\node   (E) {5};
\node   (F) {4} ;
%%
\draw   (C) -- (D)  (C) -- (E)  (C) -- (F)
        (B) -- (E)  (B) -- (D)
        (A) -- (D);
\end{tikzpicture}
%
}\hfil
\subfloat[Conflict graph \label{fig:main-b}]
{%
\begin{tikzpicture}[
    node distance = 3mm and 22mm,
      start chain = going above,
every node/.style = {shape=circle, draw=black,
    inner sep=1mm, on chain}
                    ]
\node   (A) {3};
\node   (B) {2};
\node   (C) {1};
%
\node   (D) [right=of A]    {6};
\node   (E) {5};
\node   (F) {4} ;
%%
\draw   (B) -- (F)
        (A) -- (E)  (A) -- (F);
\end{tikzpicture}
%
}
\caption{Main caption}
    \label{fig:main}
\end{figure}
\end{document}

ご覧のとおり、メインキャプションを追加するのは大したことではありません。articleテキスト幅の中央にキャプションを配置するキャプション機能です。captionパッケージを使用する場合は、それに応じてキャプションを設定する必要があります (このためには、パッケージのドキュメントを読む必要があります)。それ以外の場合は、コードをよりコンパクトにするために自由にしていますが、純粋な TikZ の図のままです。このために、ライブラリchainsとを使用しますpositioning

答え2

ここでオプションを使用するsubcaption- ボックスの幅を指定できます。したがって、幅の異なる 2 つのボックスを指定すると、.5\linewidthそれらはページに対して、また互いに対して中央に配置されます。

ここに画像の説明を入力してください

\documentclass{article}

\usepackage{graphicx,subcaption}

\begin{document}

\begin{figure}[ht]
  \centering
  \subcaptionbox{Compability graph}{%
    \includegraphics[width=80pt]{example-image-a}%
  }\hfill
  \subcaptionbox{Conflict graph}{%
    \includegraphics[width=80pt]{example-image-b}%
  }

  \bigskip

  \subcaptionbox{Compability graph}[.5\linewidth]{%
    \includegraphics[width=80pt]{example-image-a}%
  }%
  \subcaptionbox{Conflict graph}[.5\linewidth]{%
    \includegraphics[width=80pt]{example-image-b}%
  }

  \bigskip

  \subcaptionbox*{Compability graph}{%
    \includegraphics[width=80pt]{example-image-a}%
  }\hfill
  \subcaptionbox*{Conflict graph}{%
    \includegraphics[width=80pt]{example-image-b}%
  }
  \caption{A figure caption}
\end{figure}

\end{document}

*また、星付きバージョンのキャプションを使用して番号を削除し、少し余分なスペースを確保することもできます。

関連情報