Zeilenumbrüche von mathematischen Ausdrücken in der Subfloat-Umgebung

Zeilenumbrüche von mathematischen Ausdrücken in der Subfloat-Umgebung

Ich möchte eine Abbildung zeigen, in der es eine Graphdarstellung über den Kanten- und Knotenlisten in LaTeX gibt. Ich habe so etwas geschrieben:

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

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

Mein Problem ist, dass ich möchte, dass der mathematische Ausdruck für E(G) in der zweiten Subfig-Umgebung mehrere Zeilen umfasst, wenn er zu lang ist. Wenn möglich, möchte ich, dass die Überschrift „Zweite Abbildung“ auch auf der Seite zentriert ist.

Wie könnte ich mein Problem lösen?

Danke schön.

Antwort1

Eine weitere Alternative: Verwendung von arrayfür die zweite Abbildung.

Bildbeschreibung hier eingeben

Code

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

Antwort2

Es wäre möglich, einen automatischen Zeilenumbruch für die Kantenliste zu erhalten, aber eine geeignete Breite muss geschätzt werden.

subfigWenn Sie aufgrund von Dokumentklassenbeschränkungen (z. B. ) nicht gezwungen sind, zu verwenden IEEEtran, ist es meiner Meinung nach besser subcaption, und es \subcaptionboxist ähnlich wie , \subfloatda keine Breite angegeben werden muss. Für die Liste der Kanten alignedatkann verwendet werden.

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

Bildbeschreibung hier eingeben

Antwort3

Beispielsweise durch Verwendung der multlinedUmgebung (Paket mathtools) oder der alignedUmgebung des Pakets amsmath(bei dem es sich um eine Erweiterung handelt).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}

Übrigens hatte Ihr Code einen Fehler in >=stealth', das Anführungszeichen scheint fehl am Platz zu sein oder ein anderes Anführungszeichen fehlt (ich weiß nicht viel über Tikz). Ich habe mich entschieden, ihn zurückzuziehen. Es wäre sicherlich besser gewesen, ein Minimal Working Example (MWE) bereitzustellen.

Bildbeschreibung hier eingeben

Antwort4

Hier ist eine Möglichkeit, mit Stapeln.

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

Bildbeschreibung hier eingeben

Durch einfaches Verschieben der Zeilenumbrüche ( \\) in der \Longunderstackkönnte man Folgendes erreichen:

Bildbeschreibung hier eingeben

verwandte Informationen