如何用 LaTeX 寫出很長的 LP 題目?

如何用 LaTeX 寫出很長的 LP 題目?

我正在嘗試用 LaTeX 編寫一個很長的 LP 問題,大約 5-7 行。我嘗試使用 multiline 但由於某種原因它無法編譯。

這是我的程式碼:

 \begin{multline} 
 Min \quad Z = 111x_{11} + 111x_{12} + 109.25x_{13} + 111x_{14} + 113x_{15}\\
 +107.25x_{21} + 119.5x_{22} + 107.7x_{23} + 103.75x_{24} + 109.7x_{25}\\
 + x_{13} + x_{23} + x_{33} + x_{34} + x_{35}\\
 + x_{14} + x_{24} + x_{34} + x_{44} + x_{45]\\
 + x_{15} + x_{25} + x_{35} + x_{45} + x_{55}\\
 + x_{16} + x_{26} + x_{36} + x_{46} + x_{56}\\
 + x_{17} + x_{27} + x_{37} + x_{47} + x_{57}\\
 \end{multline}

如果我將目標函數寫到 x_{35},它就會編譯,但如果我要完成它,它就不會編譯。

答案1

除了替換為 之外x_{45]x_{45}您可能還需要考慮multline以嵌套的equation/aligned環境取代環境。

另外,除非某些人強迫您這樣做(可怕且非常特殊的印刷慣例),否則不要寫Min;相反,寫\min.

在此輸入影像描述

\documentclass{article}
\usepackage{amsmath} % for 'aligned' env.
\begin{document}
\noindent
Combined \texttt{equation}/\texttt{aligned} solution:
\begin{equation}\begin{aligned}[b]
\min Z &= 111x_{11} + 111x_{12} + 109.25x_{13} + 111x_{14} + 113x_{15}\\
&\quad +107.25x_{21} + 119.5x_{22} + 107.7x_{23} + 103.75x_{24} + 109.7x_{25}\\
&\quad + x_{13} + x_{23} + x_{33} + x_{34} + x_{35}\\
&\quad + x_{14} + x_{24} + x_{34} + x_{44} + x_{45}\\
&\quad + x_{15} + x_{25} + x_{35} + x_{45} + x_{55}\\
&\quad + x_{16} + x_{26} + x_{36} + x_{46} + x_{56}\\
&\quad + x_{17} + x_{27} + x_{37} + x_{47} + x_{57}
\end{aligned}\end{equation}

\bigskip\noindent
\texttt{multline} solution:
\begin{multline}
\min Z = 111x_{11} + 111x_{12} + 109.25x_{13} + 111x_{14} + 113x_{15}\\
 +107.25x_{21} + 119.5x_{22} + 107.7x_{23} + 103.75x_{24} + 109.7x_{25}\\
 + x_{13} + x_{23} + x_{33} + x_{34} + x_{35}\\
 + x_{14} + x_{24} + x_{34} + x_{44} + x_{45}\\
 + x_{15} + x_{25} + x_{35} + x_{45} + x_{55}\\
 + x_{16} + x_{26} + x_{36} + x_{46} + x_{56}\\
 + x_{17} + x_{27} + x_{37} + x_{47} + x_{57}
\end{multline}
\end{document}


附錄解決OP的後續請求,即使所有七行中的條目「更加對齊」。肯定是可能的要做到這一點,可以說需要環境的幫助array——見下文。 IMNSHO,不過,你是不是用這樣的符號來幫助你的讀者。如果這是我的論文,我會使用\sum指令來指示要對 25 個變數執行簡單求和。

(請注意,為了與後續請求中的操作保持一致,以下程式碼中的下標排序與原始答案中使用的下標排序有很大不同。)

在此輸入影像描述

\documentclass{article}
\usepackage{mathtools} 
\usepackage{array}
\newcolumntype{C}{>{{}}c<{{}}}
\begin{document}
\noindent
Combined \texttt{equation}/\texttt{aligned} solution:
\begin{equation}\begin{aligned}[b]
\min Z &= 111x_{11} + 111x_{12} + 109.25x_{13} + 111x_{14} + 113x_{15}\\
&\quad +107.25x_{21} + 119.5x_{22} + 107.7x_{23} + 103.75x_{24} + 109.7x_{25}\\
&\quad + x_{13} + x_{23} + x_{33} + x_{34} + x_{35}\\
&\quad + x_{14} + x_{24} + x_{34} + x_{44} + x_{45}\\
&\quad + x_{15} + x_{25} + x_{35} + x_{45} + x_{55}\\
&\quad + x_{16} + x_{26} + x_{36} + x_{46} + x_{56}\\
&\quad + x_{17} + x_{27} + x_{37} + x_{47} + x_{57}
\end{aligned}\end{equation}

\bigskip\noindent
``even more aligned'': combined \texttt{equation}, \texttt{aligned}, and \texttt{array}
\begin{equation}\begin{aligned}[b]
\setlength{\arraycolsep}{0pt}
\begin{array}[b]{@{} r*{6}{Cr} @{}}
\min Z &=& 111x_{11} &+& 111x_{12} &+& 109.25x_{13} &+& 111x_{14} &+& 113x_{15}\\
&+&107.25x_{21} &+& 119.5x_{22} &+& 107.7x_{23} &+& 103.75x_{24} &+& 109.7x_{25}\\
&+& x_{31} &+& x_{32} &+& x_{33} &+& x_{34} &+& x_{35}\\
&+& x_{31} &+& x_{42} &+& x_{43} &+& x_{44} &+& x_{45}\\
&+& x_{51} &+& x_{52} &+& x_{53} &+& x_{54} &+& x_{55}\\
&+& x_{61} &+& x_{62} &+& x_{63} &+& x_{64} &+& x_{65}\\
&+& x_{71} &+& x_{72} &+& x_{73} &+& x_{74} &+& x_{75}\\
\end{array}
\end{aligned}\end{equation}

\bigskip\noindent
\verb+\sum+ notation to replace rows 3 to 7:
\begin{equation}\begin{aligned}[b]
\min Z &= 111x_{11} + 111x_{12} + 109.25x_{13} + 111x_{14} + 113x_{15}\\
&\quad +107.25x_{21} + 119.5x_{22} + 107.7x_{23} + 103.75x_{24} + 109.7x_{25}\\
&\quad+ \smashoperator{\sum_{\substack{i=3,\dots,7;\\j=1,\dots,5}}} x_{ij}
\end{aligned}\end{equation}
\end{document}

相關內容