
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
私の問題は、2 番目のサブ図環境の E(G) の数式が長すぎる場合に、複数の行にまたがるようにしたいということです。可能であれば、「2 番目の図」というキャプションもページの中央に配置したいと思います。
どうすれば問題を解決できるでしょうか?
ありがとう。
答え1
別の方法として、array
2 番目の図に を使用します。
コード
\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
環境 (パッケージmathtools
) またはaligned
パッケージ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
スタックを使用する 1 つの方法を以下に示します。
\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
、次のことが実現できます。