Difference between revisions of "Documentation/FAQ/Formula/How do I change the spacing around my formula?"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Added a method to adjust math borders for existing formulas.)
m
 
(2 intermediate revisions by 2 users not shown)
Line 15: Line 15:
 
these steps:
 
these steps:
 
#Select the formula.
 
#Select the formula.
#Select '''Format-Frame'''.
+
#Select {{menu|Format|Frame}}.
 
#Select the tab page '''Wrap'''.
 
#Select the tab page '''Wrap'''.
 
#In the group '''Spacing''' on this page you can adjust the spacing around the formula.
 
#In the group '''Spacing''' on this page you can adjust the spacing around the formula.
Line 21: Line 21:
  
 
If you want to change the spacing around ''all'' formulas follow these steps:
 
If you want to change the spacing around ''all'' formulas follow these steps:
#Open the stylist ('''Format-Styles and Formatting''').
+
#Open the stylist ({{menu|Format|Styles and Formatting}}).
 
#Click the icon for frame styles (the third icon from the left).
 
#Click the icon for frame styles (the third icon from the left).
 
#Right-click '''Formula''' in the styles list.
 
#Right-click '''Formula''' in the styles list.
Line 32: Line 32:
  
 
#Open your formula.
 
#Open your formula.
#Select '''Format-Spacing'''.
+
#Select {{menu|Format|Spacing}}.
 
#Click '''Category''' and select '''Borders''' in the pop-up menu.
 
#Click '''Category''' and select '''Borders''' in the pop-up menu.
 
#You can now change the left and right margins of your formulas.
 
#You can now change the left and right margins of your formulas.
Line 39: Line 39:
  
 
To change the ''Math'' margins in all existing formulas, use a macro. This can be done as follows:
 
To change the ''Math'' margins in all existing formulas, use a macro. This can be done as follows:
# Select ''Tools-Macros-Organize Macros-OpenOffice.org Basic''
+
# Select {{menu|Tools|Macros|Organize Macros|OpenOffice Basic}}.
# Select ''My Macros-Standard-Module1'' in the tree in the left pane. If ''Module1'' does not exist in the ''Standard'', create it using the ''New'' button.
+
# Select ''My Macros-Standard-Module1'' in the tree in the left pane. If ''Module1'' does not exist in the ''Standard'', create it using the {{button|New}} button.
# Select the ''Main'' macro in the right pane
+
# Select the ''Main'' macro in the right pane.
# Click the ''Edit'' button.
+
# Click the {{button|Edit}} button.
 
# Add the ''SetMathBorder'' code after the main Sub:  
 
# Add the ''SetMathBorder'' code after the main Sub:  
#: <pre>
 
 
#: Main sub
 
#: Main sub
 
#:
 
#:
 
#: End sub
 
#: End sub
#:
 
 
#: Sub SetMathBorder
 
#: Sub SetMathBorder
#: dim embeddedObjects, elementNames, i, element
+
#:: On Error Resume Next ' Prevents deleted objects from causing errors.
#:
+
#:: dim embeddedObjects, elementNames, i, element, elem, oldW
#:   embeddedObjects = ThisComponent.getEmbeddedObjects()
+
#:: embeddedObjects = ThisComponent.getEmbeddedObjects()
#:   elementNames = embeddedObjects.getElementNames()
+
#:: elementNames = embeddedObjects.getElementNames()
#:   for i=0 to UBOUND(elementNames)
+
#:: for i=0 to UBOUND(elementNames)
#:       element = embeddedObjects.getByName(elementNames(i)).Model
+
#::: elem = embeddedObjects.getByName(elementNames(i))
#:       if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
+
#::: element = elem.Model
#:         element.TopMargin = 30 : rem sets to 0.30 mm
+
#::: if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
#:         element.BottomMargin = 30
+
#:::: oldW = elem.Width - element.LeftMargin - element.RightMargin ' captures old widths
#:         element.LeftMargin = 30
+
#:::: element.TopMargin = 0 ' sets internal border to zero
#:         element.RightMargin = 30
+
#:::: element.BottomMargin = 0 ' You can adjust these values(It's just that I use the formulas in text so I prefer it to be 0)
#:       endif
+
#:::: element.LeftMargin = 0
#:   next i
+
#:::: element.RightMargin = 0
#:   ThisComponent.reformat()  
+
#:::: ' adjusts the width, as openoffice sometimes stretches the formula as opposed to resizing it.
#: End Sub </pre>
+
#:::: elem.Width = oldW + element.LeftMargin + element.RightMargin
# Switch to the window containing your document, and select Select ''Tools-Macros-Run Macro''
+
#::: endif
 +
#:: next i
 +
#:: ThisComponent.reformat()
 +
#: End Sub
 +
#:
 +
# Switch to the window containing your document, and select {{menu|Tools|Macros|Run Macro}}.
 
# Select ''My Macros-Standard-Module1'' in the tree in the left pane (Library).
 
# Select ''My Macros-Standard-Module1'' in the tree in the left pane (Library).
 
# Select ''SetMathBorder'' in the right pane (Macro name).
 
# Select ''SetMathBorder'' in the right pane (Macro name).
# Click the ''Run'' button
+
# Click the {{button|Run}} button. In my case, the screen is not updated correctly. An update can be triggered by minimizing and restoring, going to a different page in the document, or changing the zoom.
  
 
<section end=answer/>
 
<section end=answer/>
  
 
[[Category:Documentation/FAQ/Formula]]
 
[[Category:Documentation/FAQ/Formula]]

Latest revision as of 13:34, 7 October 2021


How do I change the spacing around my formula?



If you have embedded your formula in a Writer document you can do as follows.


If you want to change the spacing around a single formula follow these steps:

  1. Select the formula.
  2. Select Format → Frame.
  3. Select the tab page Wrap.
  4. In the group Spacing on this page you can adjust the spacing around the formula.


If you want to change the spacing around all formulas follow these steps:

  1. Open the stylist (Format → Styles and Formatting).
  2. Click the icon for frame styles (the third icon from the left).
  3. Right-click Formula in the styles list.
  4. Select Modify in the pop-up menu.
  5. Select the tab page Wrap.
  6. In the group Spacing on this page you can adjust the spacing around the formulas.


In addition Math inserts some spacing within the frame around your formula. Follow these steps to change this:

  1. Open your formula.
  2. Select Format → Spacing.
  3. Click Category and select Borders in the pop-up menu.
  4. You can now change the left and right margins of your formulas.
  5. If you want to set these margins as the default, press Default and confirm.


To change the Math margins in all existing formulas, use a macro. This can be done as follows:

  1. Select Tools → Macros → Organize Macros → OpenOffice Basic.
  2. Select My Macros-Standard-Module1 in the tree in the left pane. If Module1 does not exist in the Standard, create it using the  New  button.
  3. Select the Main macro in the right pane.
  4. Click the  Edit  button.
  5. Add the SetMathBorder code after the main Sub:
    Main sub
    End sub
    Sub SetMathBorder
    On Error Resume Next ' Prevents deleted objects from causing errors.
    dim embeddedObjects, elementNames, i, element, elem, oldW
    embeddedObjects = ThisComponent.getEmbeddedObjects()
    elementNames = embeddedObjects.getElementNames()
    for i=0 to UBOUND(elementNames)
    elem = embeddedObjects.getByName(elementNames(i))
    element = elem.Model
    if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
    oldW = elem.Width - element.LeftMargin - element.RightMargin ' captures old widths
    element.TopMargin = 0 ' sets internal border to zero
    element.BottomMargin = 0 ' You can adjust these values(It's just that I use the formulas in text so I prefer it to be 0)
    element.LeftMargin = 0
    element.RightMargin = 0
    ' adjusts the width, as openoffice sometimes stretches the formula as opposed to resizing it.
    elem.Width = oldW + element.LeftMargin + element.RightMargin
    endif
    next i
    ThisComponent.reformat()
    End Sub
  6. Switch to the window containing your document, and select Tools → Macros → Run Macro.
  7. Select My Macros-Standard-Module1 in the tree in the left pane (Library).
  8. Select SetMathBorder in the right pane (Macro name).
  9. Click the  Run  button. In my case, the screen is not updated correctly. An update can be triggered by minimizing and restoring, going to a different page in the document, or changing the zoom.


Personal tools