Saltos de línea de expresiones matemáticas en un entorno subflotante

Saltos de línea de expresiones matemáticas en un entorno subflotante

Me gustaría mostrar una figura en la que hay una representación gráfica encima de su borde y listas de nodos en LaTeX. He escrito algo como esto:

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

Salida http://imageshack.com/a/img196/7216/y3ms.png

Mi problema es que me gustaría que la expresión matemática para E(G) en el segundo entorno de subfigura se extienda a lo largo de varias líneas si es demasiado larga. Si es posible, me gustaría que el título "Segunda figura" también estuviera centrado en la página.

¿Cómo podría solucionar mi problema?

Gracias.

Respuesta1

Otra alternativa: uso de arraypara la segunda figura.

ingrese la descripción de la imagen aquí

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}

Respuesta2

Sería posible obtener un salto de línea automático para la lista de bordes, pero es necesario adivinar un ancho adecuado.

Si no está obligado a usarlo subfigdebido a restricciones de clase de documento (por ejemplo, IEEEtran), creo que es mejor usarlo subcaptiony \subcaptionboxes similar a \subfloatque no necesita especificar un ancho. Para la lista de aristas, alignedatse puede utilizar.

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

ingrese la descripción de la imagen aquí

Respuesta3

Utilizando el multlinedentorno (paquete mathtools) o el alignedentorno del paquete amsmath(del cual mathtoolses una extensión), por ejemplo.

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

Por cierto, tu código tuvo un error en >=stealth', la cita parece estar fuera de lugar o falta otra cita (no sé mucho sobre tikz). Elegí retirarlo. Sin duda, hubiera sido mejor proporcionar un ejemplo mínimo de trabajo (MWE).

ingrese la descripción de la imagen aquí

Respuesta4

Esta es una forma, con pilas.

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

ingrese la descripción de la imagen aquí

Simplemente cambiando los saltos de línea ( \\) en el \Longunderstack, se podría lograr esto:

ingrese la descripción de la imagen aquí

información relacionada