
我想展示一個圖形,其中在 LaTeX 中其邊緣和節點列表上方有一個圖形表示。我寫過這樣的東西:
\begin{figure}[!ht]
\subfloat[First figure]{
\centering
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto, node distance=3cm,
thick, main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (v1) at (-2,2) {2};
\node[main node] (v2) at (2,2) {3};
\node[main node] (v3) at (4,0) {6};
\node[main node] (v4) at (2,-2) {4};
\node[main node] (v5) at (-2,-2) {5};
\node[main node] (v6) at (-4,0) {1};
\draw (v1) edge (v2);
\draw (v2) edge (v3);
\draw (v3) edge (v4);
\draw (v4) edge (v5);
\draw (v5) edge (v6);
\draw (v6) edge (v1);
\draw (v5) edge (v1);
\draw (v5) edge (v2);
\draw (v4) edge (v2);
\end{tikzpicture}
}
\subfloat[Second figure]{
$V(G) = \{1, 2, 3, 4, 5, 6\}$
$E(G) = \{(1, 2), (2, 1), (1, 5), (5, 1), (2, 5), (5, 2), (2, 3), (3, 2), (5, 3), (3, 5), (5, 4), (4, 5), (3, 4), (4, 3), (3, 6), (6, 3), (4, 6), 6, 5)\}$
}
\caption[Graph representation]{Graph representation.}
\label{fig:graphexample}
\end{figure}
輸出http://imageshack.com/a/img196/7216/y3ms.png
我的問題是,如果第二個子圖環境中的 E(G) 數學表達式太長,我希望它能夠跨越多行。如果可能的話,我希望標題「第二張圖」也位於頁面的中心。
我該如何解決我的問題?
謝謝。
答案1
另一種選擇:使用array
第二個數字。
程式碼
\documentclass{article}
\usepackage{tikz,subfig}
\usetikzlibrary{arrows}
\begin{document}
\begin{figure}[!ht]
\centering
\subfloat[First figure]{
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto, node distance=3cm, thick,
main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (v1) at (-2,2) {2};
\node[main node] (v2) at (2,2) {3};
\node[main node] (v3) at (4,0) {6};
\node[main node] (v4) at (2,-2) {4};
\node[main node] (v5) at (-2,-2) {5};
\node[main node] (v6) at (-4,0) {1};
\draw (v1) edge (v2);
\draw (v2) edge (v3);
\draw (v3) edge (v4);
\draw (v4) edge (v5);
\draw (v5) edge (v6);
\draw (v6) edge (v1);
\draw (v5) edge (v1);
\draw (v5) edge (v2);
\draw (v4) edge (v2);
\end{tikzpicture}
}\\
\subfloat[Second figure]{$
\begin{array}{lll}
V(G) &=& \{1, 2, 3, 4, 5, 6\}\\
E(G) &=& \{(1, 2), (2, 1), (1, 5), (5, 1), (2, 5),(5, 2), \\
&&(2, 3), (3, 2), (5, 3), (3, 5), (5, 4), (4, 5),\\
&&(3, 4), (4, 3), (3, 6), (6, 3), (4, 6), 6, 5)\}
\end{array}$
}
\caption[Graph representation]{Graph representation.}
\label{fig:graphexample}
\end{figure}
\end{document}
答案2
可以對邊緣列表進行自動換行,但需要猜測合適的寬度。
subfig
如果由於文件類限制(例如)而不必強制使用IEEEtran
,我相信最好使用subcaption
它,它與不需要指定寬度\subcaptionbox
類似。\subfloat
對於邊列表,alignedat
可以使用。
\documentclass{article}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{figure}[htp]
\centering
\subcaptionbox{First figure}{%
\begin{tikzpicture}[
>=stealth',
shorten >=1pt,
auto,
node distance=3cm,
thick,
main node/.style={circle,draw,font=\sffamily\Large\bfseries}
]
\node[main node] (v1) at (-2,2) {2};
\node[main node] (v2) at (2,2) {3};
\node[main node] (v3) at (4,0) {6};
\node[main node] (v4) at (2,-2) {4};
\node[main node] (v5) at (-2,-2) {5};
\node[main node] (v6) at (-4,0) {1};
\draw (v1) edge (v2);
\draw (v2) edge (v3);
\draw (v3) edge (v4);
\draw (v4) edge (v5);
\draw (v5) edge (v6);
\draw (v6) edge (v1);
\draw (v5) edge (v1);
\draw (v5) edge (v2);
\draw (v4) edge (v2);
\end{tikzpicture}%
}
\medskip
\subcaptionbox{Second figure}{%
$\!\begin{alignedat}{2}
V(G) &= \{&& 1, 2, 3, 4, 5, 6\} \\
E(G) &= \{&& (1, 2), (2, 1), (1, 5), (5, 1), (2, 5), (5, 2),\\
&&& (2, 3), (3, 2), (5, 3), (3, 5), (5, 4), (4, 5),\\
&&& (3, 4), (4, 3), (3, 6), (6, 3), (4, 6), 6, 5)\}
\end{alignedat}$%
}
\caption[Graph representation]{Graph representation.}
\label{fig:graphexample}
\end{figure}
\end{document}
答案3
例如,透過使用multlined
環境(package mathtools
)或aligned
package的環境amsmath
(其是擴展)。mathtools
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{subfig, tikz}
\begin{document}
\begin{figure}[!ht]
\centering
\subfloat[First figure]{%
\begin{tikzpicture}[>=stealth, shorten >=1pt, auto, node distance=3cm,
thick, main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (v1) at (-2,2) {2};
\node[main node] (v2) at (2,2) {3};
\node[main node] (v3) at (4,0) {6};
\node[main node] (v4) at (2,-2) {4};
\node[main node] (v5) at (-2,-2) {5};
\node[main node] (v6) at (-4,0) {1};
\draw (v1) edge (v2);
\draw (v2) edge (v3);
\draw (v3) edge (v4);
\draw (v4) edge (v5);
\draw (v5) edge (v6);
\draw (v6) edge (v1);
\draw (v5) edge (v1);
\draw (v5) edge (v2);
\draw (v4) edge (v2);
\end{tikzpicture}}
\subfloat[Second figure]{%
$\begin{aligned}[t]
V(G) &= \{1, 2, 3, 4, 5, 6\},\\
E(G) &= \begin{aligned}[t]\{%
& (1, 2), (2, 1), (1, 5), (5, 1), (2, 5),\\
& (5, 2), (2, 3),(3, 2), (5, 3), (3, 5),\\
& (5, 4), (4, 5), (3, 4), (4, 3),\\
& (3, 6), (6, 3), (4, 6), (6, 5)\}
\end{aligned}
\end{aligned}$}
\caption[Graph representation]{Graph representation.}
\label{fig:graphexample}
\end{figure}
\end{document}
順便說一句,您的程式碼有一個錯誤>=stealth'
,引用似乎不合適,或者缺少另一個引用(我對 tikz 不太了解)。我選擇撤回。提供一個最小工作範例(MWE)肯定會更好。
答案4
這是一種方法,使用堆疊。
\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[usestackEOL]{stackengine}
\stackMath
\begin{document}
\begin{figure}[!ht]
\centering
\subfloat[First figure]{
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto, node distance=3cm,
thick, main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (v1) at (-2,2) {2};
\node[main node] (v2) at (2,2) {3};
\node[main node] (v3) at (4,0) {6};
\node[main node] (v4) at (2,-2) {4};
\node[main node] (v5) at (-2,-2) {5};
\node[main node] (v6) at (-4,0) {1};
\draw (v1) edge (v2);
\draw (v2) edge (v3);
\draw (v3) edge (v4);
\draw (v4) edge (v5);
\draw (v5) edge (v6);
\draw (v6) edge (v1);
\draw (v5) edge (v1);
\draw (v5) edge (v2);
\draw (v4) edge (v2);
\end{tikzpicture}
}
\subfloat[Second figure]{
\def\stackalignment{l}
\stackunder[8pt]{\kern-.3pt$V(G) = \{1, 2, 3, 4, 5, 6\}$}
{$E(G) = \Longunderstack[r]{\{(1, 2), (2, 1), (1, 5), (5, 1), (2, 5),\\
(5, 2), (2, 3), (3, 2), (5, 3), (3, 5),\\
(5, 4), (4, 5), (3, 4), (4, 3), (3, 6),\\
(6, 3), (4, 6), (6, 5)\}\kern-2.3pt}$
}}
\caption[Graph representation]{Graph representation.}
\label{fig:graphexample}
\end{figure}
\end{document}
\\
只需將中的換行符 ( ) 移動一下\Longunderstack
,就可以實現這一目標: