模板:NumBlk/sandbox

![]() | 这是Template:NumBlk(差异)的沙盒。 参见本模板的测试样例。 |
![]() | 本模板使用以下模板样式: |
![]() | 此模板使用Lua语言: |
此模板可用于编号数学公式与化学式。可和{{EquationRef}}同时使用,用于加入来源引用。另外,也可以直接改用{{NumBlk2}}——一个具备{{NumBlk}}与{{EquationRef}}两者主要功能的模板。
警告:当此模板与前导冒号
:
、前导星号*
或前导井字号#
一起使用时,可能会导致lint错误(英文说明)。更多信息,请参阅§ 通过参数|2=
以外的方式做缩进、§ 无序清单和§ 有序清单。
参数
[编辑]参数|1=
、|2=
和|3=
是必须的。另外还有可选参数|Attr=
、|RawN=
、|Cl=
、|LnSty=
和|Border=
。
|1=
- 设置缩进。放置的冒号
:
越多,块缩进的层数就越多。若不需缩进,此参数应赋空值。
- 设置缩进。放置的冒号
|2=
- 内容。
|3=
- 编号。此模板并不会剪去(trim)编号首尾的空白字符,参见§ 编号与空白字符。
|Attr=
|RawN=
- 赋予之值若为空值或全由空白字符组成则此参数失效,否则此参数生效。当此参数生效时,移除编号和括号的格式。
|Cl=
- 此参数之值会被加进模板最外层元素的
class
属性里,所以此参数需符合class
属性的语法,是一个以空格分隔的class列表。class
属性允许CSS通过class选择器(class selector)来设置样式。此模板所使用的模板样式包含了以下classes:numblk
- 主要作为识别{{NumBlk}}模板的用途,此class会被自动加进此模板最外层元素的
class
属性里。 numblk-raw-n
- 当
|RawN=
生效时,此class会被自动加进模板最外层元素的class
属性里。模板最外层元素的class
属性里包含此class时,模版会被调整为|RawN=
生效时其说明所描述的样式。 numblk-border
- 当
|Border=
生效时,此class会被自动加进模板最外层元素的class
属性里。模板最外层元素的class
属性里包含此class时,模版会被调整为|Border=
生效时其说明所描述的样式。
- 此参数之值会被加进模板最外层元素的
|LnSty=
- 设置线样式。
|Border=
- 赋予之值若为空值或全由空白字符组成则此参数失效,否则此参数生效。当此参数生效时,将显示边框。(试验用途)
示例
[编辑]
可生成HTML的公式[编辑] | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
缩进[编辑] | ||||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
公式编号格式[编辑] | ||||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
线样式[编辑] | ||||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
|
| |||||||||
通过参数[编辑] | ||||||||||
以下的方程式
:<math>3x+2y-z=1</math>
::<math>2x-2y+4z=-2</math>
:::<math>-2x+y-2z=0</math>
形成三個方程式的方程組。
|
以下的方程式 形成三个方程式的方程组。 | |||||||||
以下的方程式
:{{NumBlk||<math>3x+2y-z=1</math>|1}}
::{{NumBlk||<math>2x-2y+4z=-2</math>|2}}
:::{{NumBlk||<math>-2x+y-2z=0</math>|3}}
形成三個方程式的方程組。
|
||||||||||
以下的方程式
<dl><dd>
{{NumBlk||<math>3x+2y-z=1</math>|1}}
<dl><dd>
{{NumBlk||<math>2x-2y+4z=-2</math>|2}}
<dl><dd>
{{NumBlk||<math>-2x+y-2z=0</math>|3}}
</dd></dl>
</dd></dl>
</dd></dl>
形成三個方程式的方程組。
|
以下的方程式
形成三个方程式的方程组。 | |||||||||
以下的方程式
<div style="margin-left: 1.6em;">
{{NumBlk||<math>3x+2y-z=1</math>|1}}
<div style="margin-left: 1.6em;">
{{NumBlk||<math>2x-2y+4z=-2</math>|2}}
<div style="margin-left: 1.6em;">
{{NumBlk||<math>-2x+y-2z=0</math>|3}}
</div>
</div>
</div>
形成三個方程式的方程組。
|
以下的方程式
形成三个方程式的方程组。 | |||||||||
以下的方程式
<div style="margin-left: calc(1.6em * 1);">
{{NumBlk||<math>3x+2y-z=1</math>|1}}
</div>
<div style="margin-left: calc(1.6em * 2);">
{{NumBlk||<math>2x-2y+4z=-2</math>|2}}
</div>
<div style="margin-left: calc(1.6em * 3);">
{{NumBlk||<math>-2x+y-2z=0</math>|3}}
</div>
形成三個方程式的方程組。
|
以下的方程式
形成三个方程式的方程组。 | |||||||||
无序清单[编辑] | ||||||||||
* <math>3x+2y-z=1</math>
* <math>2x-2y+4z=-2</math>
* <math>-2x+y-2z=0</math>
|
| |||||||||
* {{NumBlk||<math>3x+2y-z=1</math>|1}}
* {{NumBlk||<math>2x-2y+4z=-2</math>|2}}
* {{NumBlk||<math>-2x+y-2z=0</math>|3}}
|
||||||||||
{{Bulleted list
|1=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>3x+2y-z=1</math>|Eq. 1}}</div>
|2=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>2x-2y+4z=-2</math>|Eq. 2}}</div>
|3=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>-2x+y-2z=0</math>|Eq. 3}}</div>
}}
|
| |||||||||
{{Bulleted list
|1=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>3x+2y-z=1</math>|Eq. 1}}</div>
|2=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>2x-2y+4z=-2</math>|Eq. 2}}</div>
|3=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>-2x+y-2z=0</math>|Eq. 3}}</div>
}}
|
| |||||||||
有序清单[编辑] | ||||||||||
# <math>3x+2y-z=1</math>
# <math>2x-2y+4z=-2</math>
# <math>-2x+y-2z=0</math>
|
| |||||||||
# {{NumBlk||<math>3x+2y-z=1</math>|1}}
# {{NumBlk||<math>2x-2y+4z=-2</math>|2}}
# {{NumBlk||<math>-2x+y-2z=0</math>|3}}
|
||||||||||
{{Ordered list
|1=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>3x+2y-z=1</math>|Eq. 1}}</div>
|2=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>2x-2y+4z=-2</math>|Eq. 2}}</div>
|3=<div style="display: inline-block; width: 100%; vertical-align: middle;">{{NumBlk||<math>-2x+y-2z=0</math>|Eq. 3}}</div>
}}
|
| |||||||||
{{Ordered list
|1=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>3x+2y-z=1</math>|Eq. 1}}</div>
|2=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>2x-2y+4z=-2</math>|Eq. 2}}</div>
|3=<div style="display: inline-table; width: 100%; vertical-align: middle;">{{NumBlk||<math>-2x+y-2z=0</math>|Eq. 3}}</div>
}}
|
| |||||||||
边框[编辑] | ||||||||||
<!-- 未指定 LnSty -->
{{NumBlk|:|<math>y=ax+b</math>|Eq. 3|Border=1}}
|
| |||||||||
<!-- 指定 LnSty -->
{{NumBlk|:|<math>y=ax+b</math>|Eq. 3|LnSty=0.7em solid #e500e5|Border=1}}
|
|
Positioning relative to surrounding images
[编辑]Numbered blocks should be able to be placed around images that take up space on the left or right side of the screen. To ensure numbered block has access to the entire line, consider using a {{clear}}-like template.
To illustrate, consider the example:
[[Image:Bnet_fan2.png|frame|right|Fig.1: Bayesian Network representation of Eq.(6)]] [[Image:Bnet_fan2.png|frame|left|Fig.1: Bayesian Network representation of Eq.(6)]] <br><br>A Bayesian network (or a belief network) is a probabilistic graphical model that represents a set of variables and their probabilistic independencies. For example, a Bayesian network could represent the probabilistic relationships between diseases and symptoms. Given symptoms, the network can be used to compute the probabilities of the presence of various diseases. {{NumBlk|1=:|2=<math> P(a, b, \lambda) = P(a| \lambda) P(b | \lambda) P(\lambda)\, </math>,|3='''Eq.(6)'''|RawN=.}}


A Bayesian network (or a belief network) is a probabilistic graphical model that represents a set of
variables and their probabilistic independencies. For example, a Bayesian network could represent the
probabilistic relationships between diseases and symptoms. Given symptoms, the network can be used to compute
the probabilities of the presence of various diseases.
, | Eq.(6) |
If it is desirable for the numbered block to span the entire line, a {{clear}} should be placed before it.
[[Image:Bnet_fan2.png|frame|right|Fig.1: Bayesian Network representation of Eq.(6)]] [[Image:Bnet_fan2.png|frame|left|Fig.1: Bayesian Network representation of Eq.(6)]] <br><br>A Bayesian network (or a belief network) is a probabilistic graphical model that represents a set of variables and their probabilistic independencies. For example, a Bayesian network could represent the probabilistic relationships between diseases and symptoms. Given symptoms, the network can be used to compute the probabilities of the presence of various diseases. {{clear}} {{NumBlk|1=:|2=<math> P(a, b, \lambda) = P(a| \lambda) P(b | \lambda) P(\lambda)\, </math>,|3='''Eq.(6)'''|RawN=.}}


A Bayesian network (or a belief network) is a probabilistic graphical model that represents a set of
variables and their probabilistic independencies. For example, a Bayesian network could represent the
probabilistic relationships between diseases and symptoms. Given symptoms, the network can be used to compute
the probabilities of the presence of various diseases.
, | Eq.(6) |
编号与空白字符
[编辑] 说明:为了确保
id
属性都是独一无二的,所以编号部分可能有稍作修改而与原始来源中的编号略有不同。
部分用户可能会为了增加模板wikitext的可读性而在编号前后加入换行或其他的空白字符,编号首尾额外加入的空白字符在某些情况下并不会影响模板的呈现效果,然而在其余的情况下还是可能会导致模板呈现出非预期的结果。
例如在Bias in the introduction of variation § One-step adaptive walks之中有一个如同下方的模板调用,可以看到在编号的前后出现了换行,该模板调用在英文版所呈现的结果正常,但在中文版因为此模板不会剪去编号首尾的空白字符而造成非预期的结果:
{{NumBlk|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
{{EquationRef|beta1A}}
}}
|
其中一种解决方案是使用HTML注解将编号首尾的换行等空白字符包裹起来,使模板在解析时忽略这些空白字符。为了增加一致性与可读性,以下示例将编号部分之外的空白字符也放入注解内:
<!--
-->{{NumBlk|:|<!--
--><math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|<!--
-->{{EquationRef|beta1B}}<!--
-->}}<!--
-->
另一种更简便的解决方案是改成使用命名参数(named parameter),使用命名参数时参数名与参数值首尾的空白字符会被自动去除,而命名参数的形式为參數名=參數值
。此模板编号的参数名为3
,因此改成3=參數值
的形式即可,3
与參數值
首尾的空白字符会被自动去除:
{{NumBlk|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
3 = {{EquationRef|beta1C}}
}}
Table caveat
[编辑]Because {{NumBlk}} is implemented as a table, putting {{NumBlk}} within a table yields a nested table. Due to a bug in Mediawiki's handling of nested tables, {{NumBlk}} must be used carefully in this case. In particular, when indentation for the outer table is desired, use explicit <dl><dd> and </dd></dl> tags for indentation instead of a leading colon (:).
For example,
<dl><dd> {| |<math>(f * g)[n]\,</math> |{{NumBlk||<math>\stackrel{\mathrm{def}}{=}\sum_{m=-\infty}^{\infty} f[m]\cdot g[n - m]\,</math>| 3=<span style="color:darkred;">'''(Eq.1)'''</span>|RawN=.}} |- | |<math>= \sum_{m=-\infty}^{\infty} f[n-m]\cdot g[m].\,</math> ([[Convolution#Commutativity|commutativity]]) |} </dd></dl>
produces
-
(Eq.1) (commutativity)
which shows how the outer <dl><dd> and </dd></dl> tags give the same indentation as a single colon (:) preceding the table should.
For another example,
<dl><dd> <dl><dd> {| |- |The first parameter for indentation still works when used inside table. {{NumBlk|::::|<math>ax^2+bx+c=0</math>|Level 4}} {{NumBlk|:::|<math>ax^2+bx+c=0</math>|Level 3}} {{NumBlk|::|<math>ax^2+bx+c=0</math>|Level 2}} {{NumBlk|:|<math>ax^2+bx+c=0</math>|Level 1}} {{NumBlk||<math>ax^2+bx+c=0</math>|Level 0}} |- |} </dd></dl> </dd></dl>
produces
-
-
The first parameter for indentation still works when used inside table. Level 4 Level 3 Level 2 Level 1 Level 0
-
which uses two sets of explicit tags to give the same indentation as two colons (::).