对齐数学公式

对齐数学公式

我正在用 Overleaf 编写数学公式和约束。这是我的代码,我还向您展示了我得到的结果(见图)。如您所见,公式排列不太整齐。我想通过对齐所有公式并给它们贴上标签(如图所示,用数字标记)来改善布局。如果有人能帮我,那将非常有帮助!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[super]{natbib}
\usepackage{comment}
\usepackage{graphicx}
\usepackage{float}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{caption}
\usepackage{adjustbox}
\usepackage{lipsum}
\usepackage{lscape}
\usepackage{multicol}
\usepackage{longtable}
\captionsetup[figure]{font=small,labelfont=bf}
\captionsetup[table]{font=small,labelfont=bf}
\usepackage[justification=centering]{caption}
\usepackage{eurosym}
\usepackage{mhchem}
\usepackage{relsize}
\usepackage[table, dvipsnames]{xcolor}
\renewcommand*\descriptionlabel[1]{\hspace\leftmargin$#1$}
\usepackage[hidelinks]{hyperref}
\usepackage{enumitem}
\usepackage{glossaries}
\makeglossaries
\newcommand{\mathgl}[2]{
    \newglossaryentry{#1}{name={#1},description={#2}}
    \begin{description}[labelwidth=2cm]
      \item[\gls{#1}]#2
    \end{description}
}
\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 

\begin{document}
\subsection{Stating the objective function} 
TextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextText

\begin{align}
\min \quad BFC \cdot \bigg(\mathlarger{\mathlarger{\sum}}_{i\in I}Fc_i \cdot u_i\bigg)
+ 
BEC \cdot \bigg(\mathlarger{\mathlarger{\sum}}_{i\in I}\mathlarger{\mathlarger{\sum}}_{j \in J}\mathlarger{\mathlarger{\sum}}_{p \in P}x_i_j_p\cdot Ec_i_j_p_y\bigg)
+
BTC \cdot \bigg(\mathlarger{\mathlarger{\sum}}_{i\in I}\mathlarger{\mathlarger{\sum}}_{j \in J}\mathlarger{\mathlarger{\sum}}_{p \in P}x_i_j_p\cdot Tc_i_j_p\bigg)
+
BWC \cdot \bigg(\mathlarger{\mathlarger{\sum}}_{i\in I}\mathlarger{\mathlarger{\sum}}_{j \in J}\mathlarger{\mathlarger{\sum}}_{p \in P}x_i_j_p\cdot Wc_i_j_p\bigg)
+
BZC \cdot \bigg(\mathlarger{\mathlarger{\sum}}_{i\in I}\mathlarger{\mathlarger{\sum}}_{j \in J}\mathlarger{\mathlarger{\sum}}_{p \in P}x_i_j_p\cdot Z_i_j_p\bigg)\cdot Zc 
\label{1}
\end{align}
 

\subsection{Stating the constraints}
The first constraint ensures that the demand of each customer is satisfied:

\begin{align}
\mathlarger{\sum}_{i\in I}x_i_j_p = D_j_p_y,  \quad && \forall j \in J,  p\in P, y \in Y\label{2}
\end{align}
\noindent The second formula makes sure that the maximum capacity of each supplier facility is not exceeded:
\begin{align}
\mathlarger{\sum}_{j\in J}\mathlarger{\sum}_{p\in P}x_i_j_p \leq u_i,  \quad && \forall i \in I \label{3}
\end{align}
\noindent Contracts with specific supplier facilities may agree on minimum allocation volumes. This is ensured by the following formula:
\begin{align}
\mathlarger{\sum}_{j\in J}\mathlarger{\sum}_{p\in P}x_i_j_p \geq V_i,  \quad && \forall i \in I \label{3}
\end{align}
\noindent Specific breweries desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:
\begin{align}
\mathlarger{\sum}_{i\in I}J_i_j_p \geq 2,  \quad && \forall j \in J,  p\in P \label{4}\\
x_i_j_p \geq b_i_j_p M_j_p
\end{align}
\noindentSpecific OpCos desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:
\begin{align}
\mathlarger{\sum}_{i\in I}F_i_o_p\geq 2,\quad && \forall o \in O,  p\in P \label{5}\\
\mathlarger{\sum}_{i\subset I}x_i_j_p \geq F_i_o_pG_o_p,\quad && \forall i \in I,  o\in O, p\in P \label{5}
\end{align}

结果

答案1

一个简单的解决方案使用单一align环境和\intertext命令。

我把序言简化为代码运行所必需的内容。另外,我认为你真的不需要使用 double \mathlarger,这会使方程编号放在方程下方,即使在使用multlined

顺便说一句,您不必amsfonts在加载时加载amssymb- 后者会为您完成。请注意,hyperref应作为最后一个包加载,极少数例外。

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{relsize}
\usepackage[hidelinks]{hyperref}

\begin{document}
\setcounter{section}{4}
\setcounter{subsection}{5}

\subsection{Stating the objective function}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
\begin{equation}
\begin{multlined}
\min \quad BFC \cdot \bigg(\mathlarger{\sum}_{i\in I}Fc_i \cdot u_i\bigg)
+
BEC \cdot \bigg(\mathop{\mathlarger{\sum}_{i\in I}\mathlarger{\sum}_{j \in J}\mathlarger{\sum}_{p \in P}x_{i j p}}\cdot Ec_{ijpy}\bigg) +{}
\\
 BTC \cdot \bigg(\mathlarger{\sum}_{i\in I}\mathlarger{\sum}_{j \in J}\mathlarger{\sum}_{p \in P}x_{ijp}\cdot Tc_{ijp}\bigg)
+
BWC \cdot \bigg(\mathlarger{\sum}_{i\in I}\mathlarger{\sum}_{j \in J}\mathlarger{\sum}_{p \in P}x_{ijp}\cdot Wc_{ijp}\bigg)
\\
+ BZC \cdot \bigg(\mathlarger{\sum}_{i\in I}\mathlarger{\sum}_{j \in J}\mathlarger{\sum}_{p \in P}x_{ijp}\cdot Z_{ijp}\bigg)\cdot Zc
\end{multlined}
\label{1}
  \end{equation}

\subsection{Stating the constraints}
The first constraint ensures that the demand of each customer is satisfied:

\begin{align}
\mathlarger{\sum}_{i\in I}&x_{ijp} = D_{jpy}, \quad && \forall j \in J, p\in P, y \in Y\label{2} \\
\intertext{The second formula makes sure that the maximum capacity of each supplier facility is not exceeded:}
\mathlarger{\sum}_{j\in J}\mathlarger{\sum}_{p\in P} &x_{ijp} \leq u_i, \quad && \forall i \in I \label{3}
\intertext{Contracts with specific supplier facilities may agree on minimum allocation volumes. This is ensured by the following formula:}
\mathlarger{\sum}_{j\in J} \mathlarger{\sum}_{p\in P} &x_{ijp}\geq V_i, \quad && \forall i \in I \label{3} \\
\intertext{Specific breweries desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:}
\mathlarger{\sum}_{i\in I}&J_{ijp} \geq 2, \quad && \forall j \in J, p\in P \label{4}\\
&x_{ijp} \geq b_{ijp} M_{jp}\\
\intertext{Specific OpCos desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:}
\mathlarger{\sum}_{i\in I}&F_{iop} \geq 2,\quad && \forall o \in O, p\in P \label{5}\\
\mathlarger{\sum}_{i\subset I}&x_{ijp} \geq F_{iop} G_{op},\quad && \forall i \in I, o\in O, p\in P \label{5}
\end{align}

\end{document} 

在此处输入图片描述

答案2

这是一个扩展的示例:

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\usepackage{lipsum}
\begin{document}
\section{Let us try}
\subsection{Stating the objective function}

%\lipsum[1]

\begin{equation}\label{1}
\begin{aligned}
\min \quad BFC  \bigg(\sum_{i\in I}Fc_i  u_i\bigg)
&+ BEC  \biggl(\sum_{i\in I} \sum_{j \in J} \sum_{p \in P} x_{ijp}  Ec_{ijp} y \biggr)    \\
&+ BTC  \biggl(\sum_{i\in I} \sum_{j \in J} \sum_{p \in P} x_{ijp}  Tc_{ijp}   \biggr)    \\
&+ BWC  \biggl(\sum_{i\in I} \sum_{j \in J} \sum_{p \in P} x_{ijp}  Wc_{ijp}   \biggr)    \\
&+ BZC  \biggl(\sum_{i\in I} \sum_{j \in J} \sum_{p \in P} x_{ijp}  Z_{ijp}    \biggr)  Zc
\end{aligned}
\end{equation}


\subsection{Stating the constraints}
The first constraint ensures that the demand of each customer is satisfied:

\begin{align}\label{2}\allowdisplaybreaks
&\sum_{i\in I} x_{ijp} = D_{jpy},  \quad && \forall j \in J,  p\in P, y \in Y\\
\intertext{The second formula makes sure that the maximum}
&\sum_{j\in J}\sum_{p\in P} x_{ijp} \leq u_i,  \quad && \forall i \in I \label{3}
\intertext{Specific breweries desire to be supplied by at least two suppliers for some specific type 
of product code. This is ensured by the following two formulas:}
&\sum_{i\in I}J_{ijp} \geq 2,  \quad && \forall j \in J,  p\in P \label{4}\\
&x_{ijp} \geq b_{ijp} M_{jp}\label{5}
\end{align}
\end{document}

看看结果是否适合您。如果是,您可以轻松地扩展它。

在此处输入图片描述

答案3

我的版本没有\mathlarger,减少了括号并增加了一些其他提示。

例如,英国足球联合会第一个显示中的类似符号不表示三个量的乘积,而表示单个变量,因此\mathit减少了字母之间的间距。与其他人所说的相反,\cdot这是必要的,以避免将符号解释为“在 处求值的函数”。

应该使用\biggl(\biggr),而不仅仅是\bigg。无论如何,使用正常大小的\sum\Big版本似乎更好;\,如果下标可能与括号冲突,则添加。

检查最后一个i\subset I,似乎不合适。

你可能会考虑

\sum_{\substack{i\in I \\ j\in J \\ p\in P}}

而不是三重求和,对于双重求和也类似。

\noindent避免在显示前出现空行。如果显示后没有空行,则无需这样做(如果有空行,\noindent则会出现错误)。

\documentclass{article}
\usepackage{amsmath}

\newcommand{\tvar}[1]{\mathit{#1}}

\begin{document}

\subsection{Stating the objective function} 

Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text 
\begin{equation}\label{1}
\begin{split}
\min \tvar{BFC} &\cdot \Bigl(\,\sum_{i\in I} Fc_i \cdot u_i\Bigr)
+ 
\tvar{BEC} \cdot \Bigl(\,\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp} \tvar{Ec}_{ijpy}\Bigr)
\\
{}+
\tvar{BTC} &\cdot \Bigl(\,\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp} \tvar{Tc}_{ijp}\Bigr)
+
\tvar{BWC} \cdot \Bigl(\,\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp} \tvar{Wc}_{ijp}\Bigr)
\\
{}+
\tvar{BZC} &\cdot \Bigl(\,\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp} Z_{ijp}\Bigr) \tvar{Zc} 
\end{split}
\end{equation}

\subsection{Stating the constraints}
The first constraint ensures that the demand of each customer is satisfied:
\begin{equation}\label{2}
\sum_{i\in I}x_{ijp} = D_{jpy},  \quad \forall j \in J,  p\in P, y \in Y
\end{equation}
The second formula makes sure that the maximum capacity of each supplier facility 
is not exceeded:
\begin{equation}\label{3}
\sum_{j\in J}\sum_{p\in P}x_{ijp} \leq u_i,  \quad  \forall i \in I
\end{equation}
Contracts with specific supplier facilities may agree on minimum allocation volumes. 
This is ensured by the following formula:
\begin{equation}\label{4}
\sum_{j\in J}\sum_{p\in P}x_{ijp} \geq V_i,  \quad \forall i \in I
\end{equation}
Specific breweries desire to be supplied by at least two suppliers for some specific 
type of product code. This is ensured by the following two formulas:
\begin{equation}\label{5}
\sum_{i\in I}J_{ijp} \geq 2,  \quad \forall j \in J,  p\in P
x_{ijp} \geq b_{ijp} M_{jp}
\end{equation}
Specific OpCos desire to be supplied by at least two suppliers for some specific 
type of product code. This is ensured by the following two formulas:
\begin{alignat}{2}
&\sum_{i\in I}F_{iop}\geq 2, &\quad& \forall o \in O,  p\in P \label{6}\\
&\sum_{i\subset I}x_{ijp} \geq F_{iop}G_{op}, && \forall i \in I,  o\in O, p\in P \label{7}
\end{alignat}

\end{document}

在此处输入图片描述

这是版本\substack

在此处输入图片描述

答案4

对于第一个方程,您可以使用multline环境(在amsmath包中定义):

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{lipsum}

\begin{document}
\subsection{Stating the objective function}
\lipsum[11]
\begin{multline}\label{1}
\min \quad \mathrm{BFC}{\cdot}\bigg(\sum_{i\in I}Fc_i{\cdot} u_i\bigg)
+ \mathrm{BEC}{\cdot}\bigg(\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp}{\cdot}Ec_{ijpy}\bigg)  \\
%
+ \mathrm{BTC}{\cdot}\bigg(\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp}{\cdot}Tc_{ijp}\bigg)
+ \mathrm{BWC}{\cdot}\bigg(\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp}{\cdot}Wc_{ijp}\bigg)   \\
%
+ \mathrm{BZC}{\cdot}\bigg(\sum_{i\in I}\sum_{j \in J}\sum_{p \in P}x_{ijp}{\cdot}Z_{ijp}\bigg){\cdot}Zc
\end{multline}
\end{document}

\subsection{Stating the constraints}
The first constraint ensures that the demand of each customer is satisfied:

\begin{align}
\mathlarger{\sum}_{i\in I}x_i_j_p = D_j_p_y,  \quad && \forall j \in J,  p\in P, y \in Y\label{2}
\end{align}
\noindent The second formula makes sure that the maximum capacity of each supplier facility is not exceeded:
\begin{align}
\mathlarger{\sum}_{j\in J}\mathlarger{\sum}_{p\in P}x_i_j_p \leq u_i,  \quad && \forall i \in I \label{3}
\end{align}
\noindent Contracts with specific supplier facilities may agree on minimum allocation volumes. This is ensured by the following formula:
\begin{align}
\mathlarger{\sum}_{j\in J}\mathlarger{\sum}_{p\in P}x_i_j_p \geq V_i,  \quad && \forall i \in I \label{3}
\end{align}
\noindent Specific breweries desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:
\begin{align}
\mathlarger{\sum}_{i\in I}J_i_j_p \geq 2,  \quad && \forall j \in J,  p\in P \label{4}\\
x_i_j_p \geq b_i_j_p M_j_p
\end{align}
\noindentSpecific OpCos desire to be supplied by at least two suppliers for some specific type of product code. This is ensured by the following two formulas:
\begin{align}
\mathlarger{\sum}_{i\in I}F_i_o_p\geq 2,\quad && \forall o \in O,  p\in P \label{5}\\
\mathlarger{\sum}_{i\subset I}x_i_j_p \geq F_i_o_pG_o_p,\quad && \forall i \in I,  o\in O, p\in P \label{5}
\end{align}
\end{document}

其生产成果为:

在此处输入图片描述

一些评论:

  • 增加方程式中某些符号的大小(就您而言\sum)并不是个好主意。它们的大小是为使方程式看起来更美观而特意设计的,所以请不要破坏设计师的努力
  • 我认为BFC,,BTC等是缩写,应该用 upshape 字体书写,即应该写成\mathrm{BFC},`\mathbf{BTC}˙,等
  • 类似地c_i_j_p_y,这是错误的表示法。应该是或c_{ijpy}(最可能期望的结果)或c_{i_{j_{p_{y}}}}(最不可能的结果)
  • \cdot从数学角度来看,乘法不需要使用。无论如何,如果你坚持使用它们,那么你可以用花括号将它们括起来以减少它们周围的空间(如上面的 MWE 中所做的那样)

相关内容