MigraDoc: Spaces in MigraDoc Documents

Modified on 2017/06/22 10:22 by Thomas Hövel — Categorized as: Articles, MigraDoc Articles, MigraDoc FAQ

A space is a space is a space.
But not all spaces are equal. And they do not always behave as you expect.

Spaces in MigraDoc

MigraDoc documents can persist in text files (MigraDoc DDL (MDDDL) format). To make these files readable for humans, the files can contain line breaks and indentation.

When MigraDoc renders a document, multiple spaces (ASCII code 32, accessible through the space bar on your computer) will be treated as one because the spaces could just be the result of indentation in an MDDDL file. This is very similar to HTML where indentation can also be used to make a nice source file, but extra space is ignored by the browser during rendering.

How can I get extra spacing?

There are different ways that may or may not work, depending on what you try to achieve.

Often you can get what you want by using indentation and tab stops.

No-Break Spaces

Multiple no-break spaces will never be collapsed to a single space, so you can use that to get extra spacing.

But there is a drawback: No-break spaces (NBSP) will not get broken, as the name implies. If you place three NBSP between two words, the layout routine will treat this as one long word, so both words will always be on the same line.

The NBSP is U+00A0 in Unicode. Windows users can enter NBSP using or . To get those characters, hold down the Alt key while typing the digits on the numeric keypad.

Indentation

A common task: you want to create a bullet list and want to have extra space before and after the bullet.

The right way to achieve this: use left indentation for the body text, use a negative indentation for the first line to position the bullet, set a tab stop in line with the left indentation and add a tab after the bullet.