Разрывы строк математических выражений в среде subfloat

Разрывы строк математических выражений в среде subfloat

Я хотел бы показать рисунок, на котором есть представление графа над его ребром и списки узлов в 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, можно добиться следующего:

введите описание изображения здесь

Связанный контент