![子圖下的通用標題](https://rvso.com/image/330730/%E5%AD%90%E5%9C%96%E4%B8%8B%E7%9A%84%E9%80%9A%E7%94%A8%E6%A8%99%E9%A1%8C.png)
我如何在兩個圖的中間製作一個通用標題,我可以透過標籤引用它,以及如何刪除(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 圖片中。在這方面我使用了圖書館chains
和positioning
.
答案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}
它還允許您選擇使用帶有星號*
的標題版本來刪除編號,從而為您提供一些額外的空間。