正如标题所述:我想知道是否有一种优雅的方法以非常“连贯”的方式在乳胶文档中绘制长数学表达式。
我不知道对此最好的解决方案是什么:所以我只是想向熟悉乳胶文档中长方程式的人询问:你们是如何编写它的?
例如:我有这些方程式:
但您会注意到,这些表达式的结构并不均匀:您能给出什么建议?
\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\newpage
\item \textbf{En $i$}
\begin{align}
h_{i}^{n} = - \color{red}h_{i-1}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \right)^3 \right) &+ \color{red} h_{i}^{n+1} \color{black} \left (1+ \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \right)^3 + \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i+1}^{n} + h_{i}^{n}}{2} \right)^3 \right) \notag \\
- \color{red}h_{i}^{n+1} \color{black}\left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i+1}^{n}}{2} \right)^3 \right) \notag
\end{align}
\item \textbf{En $i = (N-1)$}
\begin{align}
h_{N-1}^{n} = - \color{red} h_{N-2}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N-2}^{n}}{2} \right)^3 \right) + \color{red} h_{N-1}^{n+1} \color{black} \left (1+ \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \right)^3 + \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N}^{n} + h_{N-1}^{n}}{2} \right)^3 \right) \notag \\
- \color{red} h_{N}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \right)^3 \right) \notag
\end{align}
\end{enumerate}
\end{document}
答案1
其中align*
和方程式分为三行:
\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\newpage
\item \textbf{En $i$}
\begin{align*}
h_{i}^{n}
= &{} - {\color{red}h_{i-1}^{n+1}} \Biggl(\frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \biggr)^3 \Biggr) \\
&{} + {\color{red} h_{i}^{n+1}} \Biggl(1+\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i-1}^{n}}{2}\right)^3 +
\frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{i+1}^{n} + h_{i}^{n}}{2}\biggr)^3 \Biggr) \\
&{} + {\color{red}h_{i}^{n+1}} \Biggl(\frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{i}^{n} + h_{i+1}^{n}}{2} \biggr)^3 \Biggr)
\end{align*}
\item \textbf{En $i = (N-1)$}
\begin{align*}
h_{N-1}^{n}
= &{} - {\color{red} h_{N-2}^{n+1}} \biggl(\frac{\Delta t}{(\Delta x)^2}
\Bigl(\frac{h_{N-1}^{n} + h_{N-2}^{n}}{2} \Bigr)^3\biggr) \\
&{} - {\color{red} h_{N-1}^{n+1}} \left (1+ \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \right)^3 + \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N}^{n} + h_{N-1}^{n}}{2} \right)^3 \right) \\
&{} - {\color{red} h_{N}^{n+1}}
\biggl(\frac{\Delta t}{(\Delta x)^2} \Bigl(\frac{h_{N-1}^{n}+ h_{N}^{n}}{2} \Bigr)^3 \Biggr)
\end{align*}
\end{enumerate}
\end{document}
答案2
这是一个类似的答案唯一的那个@Zarko 的改进之处在于它对每个方程使用 3 行而不是 2 行。它的不同之处在于使用\textcolor
而不是\color
,用较小但大小合适的方括号替换不必要的大外圆括号,并将幂 3 项“贴近”到相应的右括号。
\documentclass{article}
\usepackage{amsmath,xcolor}
\begin{document}
\begin{enumerate}
\item \textbf{En} $i$
\begin{align*}
h_{i}^{n}
= -\textcolor{red}{h_{i-1}^{n+1}}
&\biggl[\frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{i}^{n} + h_{i-1}^{n}}{2}
\biggr)^{\!\!3}\, \biggr] \\
{}+\textcolor{red}{h_{i}^{n+1}}
&\biggl[1+ \frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \biggr)^{\!\!3}
+ \frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{i+1}^{n} + h_{i}^{n}}{2}
\biggr)^{\!\!3}\, \biggr] \\
{}-\textcolor{red}{h_{i}^{n+1}}
&\biggl[\frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{i}^{n} + h_{i+1}^{n}}{2}
\biggr)^{\!\!3} \, \biggr]
\end{align*}
\item \textbf{En} $i = (N-1)$
\begin{align*}
h_{N-1}^{n}
= -\textcolor{red}{h_{N-2}^{n+1}}
&\biggl[\frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{N-1}^{n} + h_{N-2}^{n}}{2}
\biggr)^{\!\!3}\, \biggr] \\
{}+\textcolor{red}{h_{N-1}^{n+1}}
&\biggl[1+ \frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \biggr)^{\!\!3}
+ \frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{N}^{n} + h_{N-1}^{n}}{2}
\biggr)^{\!\!3}\, \biggr] \\
{}-\textcolor{red}{h_{N}^{n+1}}
&\biggl[\frac{\Delta t}{(\Delta x)^2}
\biggl(\frac{h_{N-1}^{n} + h_{N}^{n}}{2}
\biggr)^{\!\!3} \, \biggr]
\end{align*}
\end{enumerate}
\end{document}
答案3
这是一个可能的解决方案,加载geometry
以获得更合适的边距,并使用[wide=0pt]
中的键enumitem
。对于第二项,我还提出了一个解决方案multline*
。
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[wide=0pt]
\newpage
\item \textbf{En $i$}
\begin{align*}
h_{i}^{n} = - \color{red}h_{i-1}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \right)^{\!\!3} \right) & + \color{red} h_{i}^{n+1} \color{black} \biggl (1+ \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i-1}^{n}}{2} \right)^{\!\!3} + \frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i+1}^{n} + h_{i}^{n}}{2} \right)^{\!\!3} \biggr) \\
%{} & \phantom{ = }
& - \color{red}h_{i}^{n+1} \color{black}\left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{i}^{n} + h_{i+1}^{n}}{2} \right)^{\!\!3} \right) \notag
\end{align*}
\item \textbf{En $i = (N-1)$}
\begin{align*}
h_{N-1}^{n} = & - \color{red} h_{N-2}^{n+1} \color{black} \Biggl(\frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N-1}^{n} + h_{N-2}^{n}}{2} \biggr)^{\!\!3} \Biggr) \\
& + \color{red} h_{N-1}^{n+1} \color{black} \Biggl(1+ \frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \biggr)^{\!\!3} %\\
+ \frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N}^{n} + h_{N-1}^{n}}{2} \biggr)^{\!\!3}\Biggr) \\
& - \color{red} h_{N}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \right)^{\!\!3} \right)
\end{align*}
\begin{multline*}
h_{N-1}^{n} = - \color{red} h_{N-2}^{n+1} \color{black} \Biggl(\frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N-1}^{n} + h_{N-2}^{n}}{2} \biggr)^{\!\!3} \Biggr)% \\
+ \color{red} h_{N-1}^{n+1} \color{black} \Biggl(1+ \frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \biggr)^{\!\!3} \\
+ \frac{\Delta t}{(\Delta x)^2} \biggl(\frac{h_{N}^{n} + h_{N-1}^{n}}{2} \biggr)^{\!\!3}\Biggr) %\\
- \color{red} h_{N}^{n+1} \color{black} \left(\frac{\Delta t}{(\Delta x)^2} \left(\frac{h_{N-1}^{n} + h_{N}^{n}}{2} \right)^{\!\!3} \right)
\end{multline*}
\end{enumerate}
\end{document}
答案4
结构与\newcommmand
根据 Zarko 的回答,我引入了一些\newcommand
定义,以减少重复标记的数量,以突出不同术语之间的差异:
\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{enumitem}
\newcommand{\dtdxtwo}{\frac{\Delta t}{(\Delta x)^2}}
\newcommand{\redh}[1]{{\color{red}h_{#1}^{n+1}}}
\newcommand{\hcube}[2]{\biggl(\frac{h_{#1}^{n} + h_{#2}^{n}}{2} \biggr)^3}
\newcommand{\aterm}[2]{\dtdxtwo \hcube{#1}{#2}}
\begin{document}
\begin{enumerate}
\item \textbf{En} $i$
\begin{align*}
h_{i}^{n}
= &{} - \redh{i-1} \Biggl(\aterm{i}{i-1}\Biggr) \\
&{} + \redh{i} \Biggl(1+\aterm{i}{i-1}+\aterm{i+1}{i}\Biggr) \\
&{} + \redh{i} \Biggl(\aterm{i}{i+1}\Biggr)
\end{align*}
\item \textbf{En} $i = N - 1$
\begin{align*}
h_{N-1}^{n}
= &{} - \redh{N-2} \Biggl(\aterm{N-1}{N-2}\Biggr) \\
&{} - \redh{N-1} \Biggl(1+\aterm{N-1}{N}+\aterm{N}{N-1}\Biggr) \\
&{} - \redh{N} \Biggl(\aterm{N-1}{N}\Biggr)
\end{align*}
\end{enumerate}
\end{document}
我的感觉是,这种标记更容易发现不一致、符号或索引错误。此外,重复术语的差异也可以更清楚地表达出来。
最后,这种命名的机会使得用有意义的术语表达方程式成为可能。