How to: Adjust Spacing Between Paragraphs

This example shows how to adjust or eliminate spacing between paragraphs in flow content.

In flow content, extra space that appears between paragraphs is the result of margins set on these paragraphs; thus, the spacing between paragraphs can be controlled by adjusting the margins on those paragraphs. To eliminate extra spacing between two paragraphs altogether, set the margins for the paragraphs to 0. To achieve uniform spacing between paragraphs throughout an entire FlowDocument, use styling to set a uniform margin value for all paragraphs in the FlowDocument.

It is important to note that the margins for two adjacent paragraphs will "collapse" to the larger of the two margins, rather than doubling up. So, if two adjacent paragraphs have margins of 20 pixels and 40 pixels respectively, the resulting space between the paragraphs is 40 pixels, the larger of the two margin values.

The following example uses styling to set the margin for all Paragraph elements in a FlowDocument to 0, which effectively eliminates extra spacing between paragraphs in the FlowDocument.

<FlowDocument>
  <FlowDocument.Resources>
    <!-- This style is used to set the margins for all paragraphs in the FlowDocument to 0. -->
    <Style TargetType="{x:Type Paragraph}">
      <Setter Property="Margin" Value="0"/>
    </Style>
  </FlowDocument.Resources>

  <Paragraph>
    Spacing between paragraphs is caused by margins set on the paragraphs.  Two adjacent margins
    will "collapse" to the larger of the two margin widths, rather than doubling up.
  </Paragraph>

  <Paragraph>
    To eliminate extra spacing between two paragraphs, just set the paragraph margins to 0.
  </Paragraph>
</FlowDocument>
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft