我正在写一个由多行组成的方程,但是其中一行很长,我想分成一行。
例如:
\begin{equation}
\begin{aligned}
& \text{minimise} && COST = A + B \\
& \text{subject to} && A = A_1 + A_2 \\
& && B = B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7 \\ % this line is too long
\end{aligned}
\end{equation}
基于上面的例子,我想在最后一行添加一个换行符。
答案1
如果只是中断,则可以使用multlined
from mathtools
(这是 的扩展形式amsmath
)
\documentclass[a4paper]{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\begin{aligned}
& \text{minimise} && COST = A + B \\
& \text{subject to} && A = A_1 + A_2 \\
& && B = \!\begin{multlined}[t]
B_1 + B_2 + B_3 + B_4 + B_5 \\
+ B_6 + B_7 % this line is too long
\end{multlined}
\end{aligned}
\end{equation}
\end{document}
答案2
这是一个快速建议(也使用环境align
):
\documentclass[]{article}
\usepackage{amsmath}
\begin{document}
\section*{Original (\texttt{aligned})}
\begin{equation}
\begin{aligned}
& \text{minimise} && \text{COST} = A + B \\
& \text{subject to} && A = A_1 + A_2 \\
& && B = B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7 \\ % this line is too long
\end{aligned}
\end{equation}
\section*{\texttt{aligned} modified}
\begin{equation}
\begin{aligned}
& \text{minimise} && \text{COST} = A + B \\
& \text{subject to} && A = A_1 + A_2 \\
& && B = B_1 + B_2 + B_3 + B_4 + \\ & && + B_5 + B_6 + B_7 % this line is too long
\end{aligned}
\end{equation}
\section*{\texttt{align}}
\begin{align}
& \text{minimise} & \text{COST} &= A + B \\
& \text{subject to} & A &= A_1 + A_2 \\
& & B &= B_1 + B_2 + B_3 + B_4 +\\ & & & + B_5 + B_6 + B_7 % this line is too long
\end{align}
\end{document}
导致:
评论
为了避免额外的方程编号(6),您可以使用命令amsmath
,\nonumber
另请参阅这里。
答案3
\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
& \text{minimise} & COST &= A + B \\
& \text{subject to} & A &= A_1 + A_2 \\
& & B &=
\! % feature
\begin{aligned}[t]
&B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7
\\
&+\dots+B_n
\end{aligned}
\end{aligned}
\end{equation}
\end{document}
答案4
我建议这样做,使用 构建alignedat
,并且虚线两部分之间的垂直间距较小:
\documentclass[a4paper, 11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}
\usepackage{mathtools}
\newcommand{\AMod}[1]{\prescript{#1}{}{\text{Mod}}}
\newcommand{\BMod}[1]{{}^{#1}\text{Mod}}
\usepackage{mathtools, nccmath}
\begin{document}
\begin{equation}
\begin{alignedat}{2}
& \text{minimise} & \text{COST}& = A + B \\
& \text{subject to:} & \smash{\rule[-1.9\baselineskip]{0.6pt}{2.4\baselineskip}\ } A &= A_1 + A_2 \\
& & B& = B_1\begin{aligned}[t] & + B_2 + B_3+ B_4 \\[-0.5ex] & + B_5 + B_6 + B_7\end{aligned}
\end{alignedat}
\end{equation}
\end{document}