
Я хотел бы показать рисунок, на котором есть представление графа над его ребром и списки узлов в 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) во второй среде subfig охватывало несколько строк, если оно слишком длинное. Если возможно, я хотел бы, чтобы заголовок "Вторая фигура" также был центрирован на странице.
Как мне решить мою проблему?
Спасибо.
решение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
среду (пакет 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
Вот один из способов — со стеками.
\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
, можно добиться следующего: