\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}
我有上述 LaTeX 代码,并且我在 TeX SE 和 Google 上查找了如何拆分方程式。我尝试使用multline
以及split
尝试拆分方程式,使其适合边距。到目前为止,我尝试过的所有方法都没有奏效,所以我不知道该怎么做。
我想要的最终结果是下面的图像,但是整个东西(不包括环境中的东西)\text{}
被格式化为方程式,而不是纯文本:
答案1
也许
\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}
或者根据评论判断也许你想要一个内联设置
\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}
答案2
有许多可能性,一是与之合作,align
并\MoveEqLeft
随之而来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}
答案3
multline
你可以使用以下方式获得类似的效果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}
设置为\leftskip
、\rightskip
和\parfillskip
确保顶行左对齐(在分配的空间内)和底行右对齐。