跳转到内容

Template:NumBlk/doc

本页使用了标题或全文手工转换
维基百科,自由的百科全书

此模板可用于编号数学公式與化學式。可和{{EquationRef}}同时使用,用于加入来源引用。另外,也可以直接改用{{NumBlk2}}——一個具備{{NumBlk}}與{{EquationRef}}兩者主要功能的模板。

 警告當此模板與前導冒號:、前導星號*或前導井字號#一起使用時,可能會導致lint錯誤英文說明)。更多資訊,請參閱§ 透過參數|2=以外的方式做縮排§ 無序清單§ 有序清單

参数

[编辑]

参数|1=|2=|3=是必须的。另外还有可选参数|Attr=|RawN=|Cl=|LnSty=|Border=

  • |1=
    设置缩进。放置的冒號:越多,區塊縮排的層數就越多。若不需縮排,此參數應賦空值
  • |2=
    内容。
  • |3=
    编号。此模板並不會剪去(trim)編號首尾的空白字元,參見§ 編號與空白字元
  • |Attr=
    指定此模板最外層元素的屬性,可以指定多個屬性。此參數之預設值為style="margin-left: {{#expr:1.6 * 縮排的層數}}em;",其中縮排的層數是根據|1=所推算出來,所以預設此參數決定了模板的縮排。當透過此參數指定此模板最外層元素的屬性時,建議對此參數適當地賦值以取代預設值原本的作用,而得到預期的縮排效果。此外,因為class屬性已被此模板內部所使用,在此參數中直接指定class屬性可能會造問題。應改由對|Cl=賦值的方式設定class屬性。(可用於包裝模板英语Wikipedia:Wrapper templates
  • |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的公式

[编辑]

{{NumBlk|:|<math>y=ax+b</math>|Eq. 3}}

Eq. 3

{{NumBlk|:|<math>ax^2+bx+c=0</math>|Eq. 3}}

Eq. 3

{{NumBlk|:|<math>\Psi(x_1,x_2)=U(x_1)V(x_2)</math>|1}}

1

{{NumBlk|:|Fe<sup>3+</sup> + H<sub>2</sub>O<sub>2</sub> → Fe<sup>2+</sup> + HOO<sup></sup> + H<sup>+</sup>|2}}

Fe3+ + H2O2 → Fe2+ + HOO + H+ 2

{{NumBlk|:|<chem>H+ + CO3^2- -> HCO3^-</chem>|3}}

3

缩进

[编辑]

{{NumBlk||<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3.5}}

3.5

{{NumBlk|:|<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|1}}

1

{{NumBlk|::|<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|13.7}}

13.7

{{NumBlk|:::|<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|1.2}}

1.2

公式编号格式

[编辑]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=3.5|RawN=.}}

3.5

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<3.5>|RawN=.}}

<3.5>

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=[3.5]|RawN=.}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3='''[3.5]'''|RawN=.}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<math>(3.5)</math>|RawN=.}}

线样式

[编辑]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''(3.5)'''</Big>|RawN=.|LnSty=1px dashed red}}

(3.5)

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''(3.5)'''</Big>|RawN=.|LnSty=3px dashed #0a7392}}

(3.5)

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.|LnSty=3px solid green}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.|LnSty=5px dotted blue}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.|LnSty=0px solid green}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.|LnSty=5px none green}}

[3.5]

{{NumBlk|1=:|2=<math>\mathbf{a}(t)=\frac{d}{dt}\mathbf{v}(t)</math>|3=<Big>'''[3.5]'''</Big>|RawN=.|LnSty=3px double #f4c300}}

[3.5]

透過參數|2=以外的方式做縮排

[编辑]
以下的方程式
:<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}}
形成三個方程式的方程組。

結果未呈現,因為可能存在lint錯誤

在wikitext語言中將前導冒號(定義的列表寫法)與{{NumBlk}}組合使用可能會出現問題。

以下的方程式
<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>
形成三個方程式的方程組。

以下的方程式

1
2
3

形成三個方程式的方程組。

以下的方程式
<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>
形成三個方程式的方程組。

以下的方程式

1
2
3

形成三個方程式的方程組。

以下的方程式
<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>
形成三個方程式的方程組。

以下的方程式

1
2
3

形成三個方程式的方程組。

無序清單

[编辑]
* <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}}

結果未呈現,因為可能存在lint錯誤

在wikitext語言中將前導星號(普通的列表寫法)與{{NumBlk}}組合使用可能會出現問題。

{{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>
}}
  • Eq. 1
  • Eq. 2
  • Eq. 3
{{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>
}}
  • Eq. 1
  • Eq. 2
  • Eq. 3

有序清單

[编辑]
# <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}}

結果未呈現,因為可能存在lint錯誤

在wikitext語言中將前導井字號(帶有數字的列表寫法)與{{NumBlk}}組合使用可能會出現問題。

{{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>
}}
  1. Eq. 1
  2. Eq. 2
  3. Eq. 3
{{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>
}}
  1. Eq. 1
  2. Eq. 2
  3. Eq. 3

边框

[编辑]
<!-- 未指定 LnSty -->
{{NumBlk|:|<math>y=ax+b</math>|Eq. 3|Border=1}}
Eq. 3
<!-- 指定 LnSty -->
{{NumBlk|:|<math>y=ax+b</math>|Eq. 3|LnSty=0.7em solid #e500e5|Border=1}}
Eq. 3

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=.}}
Fig.1: Bayesian Network representation of Eq.(6)
Fig.1: Bayesian Network representation of Eq.(6)



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=.}}
Fig.1: Bayesian Network representation of Eq.(6)
Fig.1: Bayesian Network representation of Eq.(6)



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}}
}}

beta1A

其中一種解決方案是使用HTML註解將編號首尾的換行等空白字元包裹起來,使模板在解析時忽略這些空白字元。為了增加一致性與可讀性,以下範例將編號部份之外的空白字元也放入註解內:

<!--
-->{{NumBlk|:|<!--
	--><math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|<!--
	-->{{EquationRef|beta1B}}<!--
-->}}<!--
-->
beta1B

另一種更簡便的解決方案是改成使用命名參數(named parameter)使用命名參數時參數名與參數值首尾的空白字元會被自動去除英语Help:Template#Whitespace_handling,而命名參數的形式英语Help:Template#Parameters參數名=參數值。此模板編號的參數名為3,因此改成3=參數值的形式即可,3參數值首尾的空白字元會被自動去除:

{{NumBlk|:|
<math>\mathbb{E}[\mathbf{n}(c, a)] \propto f(c)\mu(c, a)^{\beta}</math>|
3 = {{EquationRef|beta1C}}
}}
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 (::).