如何在 Word 2007+ (2010) 公式编辑器中创建增强矩阵?
是否可以?
答案1
我认为你可以这样做...
- 插入等式。
- 从“括号”下拉菜单中,插入“带分隔符的括号”组中的第一个项目
- 选择两个框中的第一个
- 从矩阵下拉菜单中插入一个 3x3 空矩阵
- 右键单击矩阵并使用插入选项根据需要插入列和行
- 选择原来的两个框中的第二个
- 从矩阵下拉菜单中插入一个 3x1 空矩阵,然后根据需要添加行。
这样得到的分隔符与两个矩阵非常接近。要添加额外的空格,可以在步骤 (4) 之后输入一个空格,在步骤 6 之前插入一个空格。我不知道这是否是一种好的方法。
您可以使用类似这样的 VBA 来实现。这些东西对我来说都是新东西,因此无疑可以改进。如果您只定期处理少量数组大小,则可以考虑使用 VBA 生成每个数组,然后将其保存为构建块/自动文本。
Sub testInsertAugmentedMatrix1()
' Insert a test equation at the selection point
Call insertAugmentedMatrix1(Selection.Range, 2, 5)
End Sub
Sub insertAugmentedMatrix1(rng As Word.Range, RowCount As Integer, ColumnCount As Integer)
' Insert a "basic" augmented matrix at the specified range,
' with RowCount rows, ColumnCount columns, and a single column after the separator
Dim mainFunction As Word.OMathFunction
Dim subFunction As Word.OMathFunction
' Insert the framework
rng.OMaths.Add rng
With rng.OMaths(1)
Set mainFunction = .Functions.Add(.Range, wdOMathFunctionDelim, 2)
With mainFunction
.Delim.BegChar = 40
.Delim.SepChar = 124
.Delim.EndChar = 41
.Delim.Grow = True
.Delim.Shape = wdOMathShapeCentered
End With
With mainFunction.Args(1)
Set subFunction = .Functions.Add(.Range, wdOMathFunctionMat, ColumnCount * RowCount, ColumnCount)
subFunction.Range.InsertAfter " "
End With
With mainFunction.Args(2)
Set subFunction = .Functions.Add(.Range, wdOMathFunctionMat, RowCount, 1)
subFunction.Range.InsertBefore " "
End With
Set subFunction = Nothing
Set mathFunction = Nothing
End With
End Sub
VBA 中的另一种方法是构建一个“数学字符串”,如下所示:
Sub testInsertAugmentedMatrix2()
' Insert a test equation at the selection point
Call insertAugmentedMatrix2(Selection.Range, 4, 6)
End Sub
Sub insertAugmentedMatrix2(rng As Word.Range, RowCount As Integer, ColumnCount As Integer)
Const mthMatrix As Long = &H25A0 '"Black Square"
Const chrMatrixColumnDelimiter As String = "&"
Const chrMatrixRowDelimiter As String = "@"
Const mthVbar As Long = &H2502
Dim i As Integer
Dim strArray As String
strArray = ""
For i = 1 To RowCount
If i > 1 Then
strArray = strArray & chrMatrixRowDelimiter
End If
strArray = strArray & String(ColumnCount - 1, chrMatrixColumnDelimiter)
Next
rng.Text = "(" & _
ChrW(mthMatrix) & "(" & strArray & ")" & _
" " & ChrW(mthVbar) & " " & _
ChrW(mthMatrix) & "(" & String(RowCount - 1, chrMatrixRowDelimiter) & ")" & _
")"
rng.OMaths.Add rng
rng.OMaths.BuildUp
End Sub
或者,您可以使用“数学自动更正”标记 \matrix 等来代替特殊 Unicode 字符,如下所示。mathSubstitute 函数是从我的帖子在这里并且尚未经过广泛测试。我认为这可能是最易读的方法。
Sub testInsertAugmentedMatrix3()
' Insert a test equation at the selection point
Call insertAugmentedMatrix3(Selection.Range, 4, 6)
End Sub
Sub insertAugmentedMatrix3(rng As Word.Range, RowCount As Integer, ColumnCount As Integer)
Const mthMatrix As String = "\matrix"
Const chrMatrixColumnDelimiter As String = "&"
Const chrMatrixRowDelimiter As String = "@"
Const mthVbar As String = "\vbar"
Dim i As Integer
Dim strArray As String
strArray = ""
For i = 1 To RowCount
If i > 1 Then
strArray = strArray & chrMatrixRowDelimiter
End If
strArray = strArray & String(ColumnCount - 1, chrMatrixColumnDelimiter)
Next
rng.Text = mathSubstitute("(" & _
mthMatrix & "(" & strArray & ")" & _
" " & mthVbar & " " & _
mthMatrix & "(" & String(RowCount - 1, chrMatrixRowDelimiter) & ")" & _
")")
rng.OMaths.Add rng
rng.OMaths.BuildUp
End Sub
Function mathSubstitute(s As String) As String
Const bslash As String = "\"
Dim a() As String
Dim sout As String
Dim i As Integer
Dim j As Integer
Dim sac As String
sout = ""
If s <> "" Then
a = Split(s, bslash)
sout = a(LBound(a))
For i = LBound(a) + 1 To UBound(a)
Debug.Print a(i)
For j = 1 To Len(a(i))
On Error Resume Next
sac = Application.OMathAutoCorrect.Entries(bslash & Left(a(i), j)).Value
If Err.Number = 0 Then
sout = sout & sac & Mid(a(i), j + 1)
Exit For
Else
sac = ""
Err.Clear
End If
Next
If sac = "" Then sout = sout & bslash & a(i)
'Debug.Print sout
Next
End If
On Error GoTo 0
mathSubstitute = sout
End Function
Murray Sargent 有一篇论文这里描述了这些东西应该如何工作。我不认为里面的方程编号方法有效在 Word 中但它可能在其他地方也这么做。
答案2
创建一个方程对象。右键单击,更改为内联。将以下内容粘贴到其中,然后右键单击并更改为显示。
[■(&@&)│■(&@&)]
这将为您提供一个由分隔符分隔的两个 2x2 部分组成的增强矩阵。一般来说,切换到内联可以让您有机会处理生成方程式对象的代码。
答案3
这在 Word 和 OneNote 中都对我有用。
在公式编辑器中输入 [|] 和一个空格。现在您将在 | 旁边有两个占位符,您可以在其中插入两个无括号矩阵(从工具栏中)。插入两个矩阵后,您可以在 | 前后插入空格以使其更具可读性。