Quebras de linha de expressões matemáticas em ambiente subfloat

Quebras de linha de expressões matemáticas em ambiente subfloat

Gostaria de mostrar uma figura na qual há uma representação gráfica acima de sua borda e listas de nós em LaTeX. Eu escrevi algo assim:

\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}

Saída http://imageshack.com/a/img196/7216/y3ms.png

Meu problema é que eu gostaria que a expressão matemática para E(G) no segundo ambiente subfig se estendesse por várias linhas se fosse muito longa. Se possível, gostaria que a legenda "Segunda figura" também fosse centralizada na página.

Como eu poderia resolver meu problema?

Obrigado.

Responder1

Outra alternativa: uso de arraypara a segunda figura.

insira a descrição da imagem aqui

Código

\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}

Responder2

Seria possível obter quebra automática de linha para a lista de arestas, mas é necessário adivinhar uma largura adequada.

Se você não for forçado a usar subfigpor causa de restrições de classe de documento (por exemplo, IEEEtran), acredito que seja melhor usar subcaptione é \subcaptionboxsemelhante ao \subfloatfato de não precisar especificar uma largura. Para a lista de arestas, alignedatpode ser usado.

\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}

insira a descrição da imagem aqui

Responder3

Usando o multlinedambiente (pacote mathtools) ou o alignedambiente do pacote amsmath(do qual mathtoolsé uma extensão), por exemplo.

\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}

A propósito, seu código apresentou um erro >=stealth', a citação parece estar fora do lugar ou falta outra citação (não sei muito sobre tikz). Eu optei por retirá-lo. Certamente teria sido melhor fornecer um Exemplo Mínimo de Trabalho (MWE).

insira a descrição da imagem aqui

Responder4

Aqui está uma maneira, com pilhas.

\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}

insira a descrição da imagem aqui

Simplesmente mudando as quebras de linha ( \\) no \Longunderstack, pode-se conseguir isso:

insira a descrição da imagem aqui

informação relacionada