如何写出完美的方程参数描述?

如何写出完美的方程参数描述?

方程的符号或参数描述如下所示,但=参数的细节并不一致。

在此处输入图片描述

我想为这样的方程式制作一个参数列表,其中符号=和详细信息按垂直位置对齐。

where
   ...
   P   =   notional permeability factor
   N   =   number of waves
   Sd  =   damage level
   ...

环境tabular会在文本前后产生较大的间距。那么如何实现=垂直对齐呢?

提供代码如下:

\begin{equation}
\frac{H_s}{\Delta D_{n50} } = 1.0~ P^{0.13}~ \left(\frac{S_d}{N} \right)^{0.2} \xi_m^P~ \sqrt{\cot \alpha}
\end{equation}
where: 

$H_s$ = significant wave height, equal to the average of the highest 1/3 of the waves

$\Delta$  = relative buoyant density, equal to $\rho_r / \rho_w - 1$, where     $\rho_w$ is the water density

$D_{n50}$ = nominal  diameter defined in Equation (2)

$P$ = notional permeability factor

$S_d$ = damage level 

$N$ = number of waves

$\xi_m$ = breaker parameter based on mean wave period $T_m$

$\alpha$ = slope angle

答案1

为此定义您自己的环境;在这里我将其实现为两列对齐;第一列以数学模式排​​版,第二列以文本模式排版;=自动添加,并具有正确的间距。

\documentclass{article}
\usepackage{array}

\newenvironment{conditions}
  {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\par\vspace{\belowdisplayskip}}

\begin{document}
An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
where:
\begin{conditions}
 P     &  notional permeability factor \\
 N     &  number of waves \\   
 S_{d} &  damage level
\end{conditions}

\end{document}

输入图片描述

如果您的条件过长,那么您可以使用不同的环境,我称之为conditions*,基于tabularx

\documentclass{article}
\usepackage{tabularx}

\newenvironment{conditions*}
  {\par\vspace{\abovedisplayskip}\noindent
   \tabularx{\columnwidth}{>{$}l<{$} @{${}={}$} >{\raggedright\arraybackslash}X}}
  {\endtabularx\par\vspace{\belowdisplayskip}}

\begin{document}
An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
where:
\begin{conditions*}
 P    &  notional permeability factor and something 
          longer that needs to be taken at the next line\\
N     &  number of waves \\
S_{d} &  damage level
\end{conditions*}

\end{document}

在此处输入图片描述


变量符号的变体

如果需要使用不同的符号而不是=在每一行中使用,请按照以下步骤操作。

\documentclass{article}
\usepackage{array,tabularx}

\newenvironment{conditions}
  {\par\vspace{\abovedisplayskip}\noindent
   \begin{tabular}{>{$}l<{$} @{} >{${}}c<{{}$} @{} l}}
  {\end{tabular}\par\vspace{\belowdisplayskip}}

\newenvironment{conditions*}
  {\par\vspace{\abovedisplayskip}\noindent
   \tabularx{\columnwidth}{>{$}l<{$} @{}>{${}}c<{{}$}@{} >{\raggedright\arraybackslash}X}}
  {\endtabularx\par\vspace{\belowdisplayskip}}

\begin{document}
An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
where:
\begin{conditions}
 P     & =       &  notional permeability factor \\
 N     & \sim    &  number of waves \\
 S_{d} & \propto & damage level
\end{conditions}

An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
where:
\begin{conditions*}
 P     & =       & notional permeability factor and something 
                   longer that needs to be taken at the next line\\
 N     & \sim    & number of waves \\
 S_{d} & \propto & damage level
\end{conditions*}

\end{document}

在此处输入图片描述


为了使“where:”之后不出现断行,这里是第一个解决方案的变体:

\documentclass{article}
\usepackage{array}

\newenvironment{conditions}[1][where:]
  {#1 \begin{tabular}[t]{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\\[\belowdisplayskip]}

\begin{document}
An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
\begin{conditions}
 P     &  notional permeability factor \\
 N     &  number of waves \\
 S_{d} &  damage level
\end{conditions}
Some text after the equation.

\end{document}

环境conditions有一个可选参数用于改变固定的where:;因此,例如\begin{conditions}[with:]将使用“with:”。

在此处输入图片描述

另一个版本允许更长的描述,这些描述需要跨行包装:

\documentclass{article}
\usepackage{array,tabularx,calc}

\newlength{\conditionwd}
\newenvironment{conditions}[1][where:]
  {%
   #1\tabularx{\textwidth-\widthof{#1}}[t]{
     >{$}l<{$} @{${}={}$} X@{}
   }%
  }
  {\endtabularx\\[\belowdisplayskip]}

\begin{document}
An equation just to start
\begin{equation}
P+N=S_{d}
\end{equation}
\begin{conditions}
 P     &  notional permeability factor with some more text
          so this ends up to break across lines blah blah
          blah blah\\
 N     &  number of waves \\
 S_{d} &  damage level
\end{conditions}
Some text after the equation.

\end{document}

在此处输入图片描述

答案2

正如 daleif 所建议的,您可以使用 align* 环境。您可以像在表格中使用“&”一样获得对齐。以下是示例:

\documentclass{article}
\usepackage[fleqn]{amsmath}
\begin{document}

\begin{align*}
    H_s &= \text{significant wave height, equal to the average of the highest 1/3 of
    the waves}\\
    \Delta &= \text{relative buoyant density, equal to }\rho_r\text{ / }\rho_w - 
    1\text{, where }\rho_w\text{ is the water density}\\
    D_{n50} &= \text{nominal  diameter defined in Equation \eqref{eq:dn50g50}}\\
    P &= \text{notional permeability factor}\\
    S_d &= \text{damage level}\\
    N &= \text{number of waves}\\
    \xi_m &= \text{breaker parameter based on mean wave period }T_m\\
    \alpha &= \text{slope angle}
\end{align*}
\end{document}

这应该对你有用。这是输出: 输出

如果你不想所有方程式都左对齐,你可以使用 flalign* 环境,如建议的那样这里

答案3

另一种选择是使用tabbing环境:

\begin{equation}
\frac{H_s}{\Delta D_{n50} } = 1.0~ P^{0.13}~ \left(  \frac{S_d}{N} \right)^{0.2}  \xi_m^P~ \sqrt{\cot \alpha}
\end{equation}
where: 
\begin{tabbing}
\phantom{$D_{n50}\ $}\= \kill
$H_s$\> = significant wave height, equal to the average of the highest 1/3 of the waves\\
$\Delta$\> = relative buoyant density, equal to $\rho_r / \rho_w - 1$, where     $\rho_w$ is the water density\\
$D_{n50}$\> = nominal  diameter defined in Equation \eqref{eq:dn50g50}\\
$P$\> = notional permeability factor\\
$S_d$\> = damage level\\
$N$\> = number of waves\\
$\xi_m$\> = breaker parameter based on mean wave period $T_m$\\
$\alpha$\> = slope angle\\
\end{tabbing}

制表环境中的第一行将设置间距(即制表位)。该\kill命令会抑制其前面的行,否则“where:”和第一个定义之间会有一个额外的空格。

或者,您可以使用固定宽度: ,而不是\phantom{$D_{n50}\ $}(列表中最长的项目) 。\hspace{3cm}

答案4

当我遇到这个问题时,我编写了这个包eqexpl(自 2018 年 11 月 14 日起,该功能可在 CTAN 上使用)。您可以使用它添加序言

\usepackage{eqexpl}
\eqexplSetIntro{where:} % set parenthesis in the left of the first item
\eqexplSetDelim{=} % set delimiter to "="

然后在文档中

\begin{eqexpl}
  \item{P} notional permeability factor
  \item{N} number of waves
  \item{$S_d$} damage level
\end{eqexpl}

序言中提到

\usepackage{eqexpl}
\eqexplSetDelim{=}

这是文档中的

\begin{eqexpl}[25mm]
  \item{$H_s$} significant wave height, equal to the average of the
    highest 1/3 of the waves
  \item{$\Delta$} relative buoyant density, equal to $\rho_r / \rho_w - 1$,
    where $\rho_w$ is the water density
  \item{$D_{n50}$} nominal diameter defined in Equation (2)
\end{eqexpl}

你会得到

结果

GitHub 上的项目简要文件

相关内容