# How to split an equation through text?

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{float}
\usepackage{framed}
\usepackage[hang,flushmargin]{footmisc}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]

\begin{document}
\noindent \newline A \textbf{Hamiltonian path} is a directed path that goes through every node exactly once. Consider the problem of testing whether a directed graph contains a Hamiltonian path that connects two specified nodes. Let:
\begin{multline}
\nonumber HAMPATH = \{\langle G, s, t \rangle| G \text{ is a directed graph with a Hamiltonian path from } s \text{ to } t.\}
\end{multline}

\end{document}


I have the above LaTeX code, and I have looked up, on both TeX SE and Google, how to split equations. I have tried to use multline as well as split to try and cut the equation so that it fits between the margins. Nothing I have tried so far has worked, so I am at a loss as to what to do.

The final result I am after is the following image, but such that the whole thing sans the things in the \text{} environment is formatted as an equation, rather than in plain text:

• \noindent \newline  don't do that:( but you can have multiple lines in a multline by using \\  (and delete the spurious that has no \begin Aug 1 '18 at 18:43

Perhaps

   \documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{float}
\usepackage{framed}
\usepackage[hang,flushmargin]{footmisc}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]

\begin{document}

A \textbf{Hamiltonian path} is a directed path that goes through
every node exactly once. Consider the problem of testing whether a
directed graph contains a Hamiltonian path that connects two
specified nodes. Let:
\begin{align*}
\nonumber \mathit{HAMPATH} &= \{\langle G, s, t \rangle\\
&\quad{} \mid  G \text{ is a directed graph with a Hamiltonian path from }\\
&\qquad s \text{ to } t.\}
\end{align*}

\end{document}


Or judging by comments perhaps you want an inline setting

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{float}
\usepackage{framed}
\usepackage[hang,flushmargin]{footmisc}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]

\begin{document}

A \textbf{Hamiltonian path} is a directed path that goes through
every node exactly once. Consider the problem of testing whether a
directed graph contains a Hamiltonian path that connects two
specified nodes. Let:
$\mathit{HAMPATH} = \{\langle G, s, t \rangle \mid G$ is a directed graph with a Hamiltonian path from
$s$ to $t$.$\}$

\end{document}

• How can I do this, but make the split within the \text{} environment? I tried to move the & and the \\ but it just threw a ton of errors. Aug 1 '18 at 19:07
• @user83024 just close the \text do the \\  then have another \text on the next line. Aug 1 '18 at 19:08
• Is it possible to align the bottom line to the left side of the equation? I have it working, but the bottom line is right-aligned. I've tried flushleft but it hasn't worked. Aug 1 '18 at 20:42
• @user83024 you want it to go to the left of the = ?? Aug 1 '18 at 20:43
• I want to put it all on the left side of the equation space. Aug 1 '18 at 20:44

There are many possibilities, one is to work with align and \MoveEqLeft that comes with mathtools.

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]

\begin{document}
A \textbf{Hamiltonian path} is a directed path that goes through every node exactly once. Consider the problem of testing whether a directed graph contains a Hamiltonian path that connects two specified nodes. Let:
\begin{align}
\text{HAMPATH} &= \\
\MoveEqLeft[4] \{\langle G, s, t \rangle| G \text{ is a directed graph with a Hamiltonian path from } s
\text{ to } t.\}\notag
\end{align}
\end{document}


You can get a similar effect to multline with a minipage:

\documentclass[12pt]{report}
\usepackage{amsmath}

\begin{document}
A \emph{Hamiltonian path} is a directed path that goes through
every node exactly once. Consider the problem of testing whether
a directed graph contains a Hamiltonian path that connects
two specified nodes. Let
$\begin{minipage}{0.8\displaywidth} \leftskip=0pt plus 1fil \rightskip=0pt plus 1fill \parfillskip=0pt plus -1fill \mathrm{HAMPATH} = \{\langle G, s, t \rangle\mid G is a directed graph with \\ a Hamiltonian path from s to t\}. \end{minipage}$

\end{document}


The settings to \leftskip, \rightskip and \parfillskip ensure left alignment (in the allotted space) in the top line and right alignment in the bottom line.