子图下的常见标题

子图下的常见标题

我怎样才能在两个图的中间创建一个共同的标题,以便通过标签引用,以及如何删除(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}

它还允许您选择使用带星号*的标题版本删除编号,从而为您提供一些额外的空间。

相关内容