子圖下的通用標題

子圖下的通用標題

我如何在兩個圖的中間製作一個通用標題,我可以透過標籤引用它,以及如何刪除(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)),那麼您將失去引用它們的能力。對於一條線來說,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 圖片中。在這方面我使用了圖書館chainspositioning.

答案2

這是一個使用的選項subcaption- 它允許您指定框的寬度。因此,如果您指定兩個框,每個框的寬度.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}

它還允許您選擇使用帶有星號*的標題版本來刪除編號,從而為您提供一些額外的空間。

相關內容