Adjusting Space Between Lines of Text Programmatically

Formatting matters. It shapes how your readers absorb your content. One crucial element? The space between lines of text.

Whether you’re preparing a report, crafting an eBook, or building dynamic documents programmatically, controlling line spacing boosts clarity and enhances professional appeal.

This guide dives deep into how to adjust line space in Word—manually and programmatically using the UniOffice SDK by Unidoc.

Why Line Spacing Matters

Line spacing isn’t just cosmetic.

It affects readability, pacing, and the visual rhythm of your text.

Too much spacing makes your document look bloated. Too little? It feels cramped.

Knowing how to reduce space between lines in Word, or how to increase it, ensures a better experience for your audience.

What Is Line Spacing?

Line spacing (also called line space or linespace) is the vertical distance between lines of text.

Common types include:

  • Single spacing: The default line spacing in most word processors.

  • Double spacing: Often used in academic and legal documents.

  • Custom spacing: Set manually or programmatically for specific design goals.

Understanding how to control this spacing is key to producing polished, legible documents.

When Should You Adjust Line Spacing?

There are several use cases for changing line space in a document:

  • Submitting documents with strict formatting rules

  • Making long paragraphs more digestible

  • Creating space-efficient or visually elegant layouts

  • Ensuring consistency in automated reports

Knowing how to decrease space between lines in Word, or how to double space in Word online, gives you full control over presentation.

How to Change Line Spacing in Microsoft Word

Let’s start with the manual method—using Microsoft Word to adjust line spacing.

How Do I Change Space Between Lines in Word?

In Word (desktop):

  • Select the text you want to format.

  • Go to the Home tab.

  • Click on the Line and Paragraph Spacing button.

  • Choose your desired spacing (e.g., 1.0, 1.5, 2.0) or click Line Spacing Options for custom values.

How to Decrease the Space Between Lines in Word

To reduce the space between lines:

  • Highlight the paragraph.

  • Select Line Spacing Options.

  • Set Line Spacing to Exactly and input a smaller value (e.g., 10 pt).

This reduces the vertical spacing without altering font size.

How to Double Space in Word Online

If you’re working in Word Online, here’s how to add double spacing:

  • Highlight the text.

  • Click on the Home tab.

  • Select the Line and Paragraph Spacing icon.

  • Choose 2.0 for double spacing.

This is useful for school papers, legal docs, or research materials.

How to Remove Space Between Lines in Word

Sometimes Word adds extra space between paragraphs.

To remove this:

  • Select the text.

  • Right-click → Paragraph.

  • Under Spacing, set both Before and After to 0 pt.

  • Click OK.

This resets spacing to the line level only, cleaning up unnecessary gaps.

Automating Line Spacing with UniOffice SDK

Want to programmatically control line spacing in your documents?

The UniOffice SDK lets you dynamically adjust line space in Word files using Go.

Let’s walk through how it works.

Before You Begin

You’ll need:

  • A UniCloud account with a valid API key

  • Go installed on your machine

  • UniOffice SDK from UniDoc

For full setup instructions, visit the UniOffice SDK documentation.

Step 1: Clone the Example Repository

In your terminal, clone the examples repo from GitHub:

git clone https://github.com/unidoc/unioffice-examples

Now navigate to the correct example folder:

cd unioffice-examples/document/line-spacing/

This folder contains all the code you need to adjust linespace in a Word file.

Step 2: Understanding the Code

Here’s the full example for setting line spacing using UniOffice:

package main

import (
	"log"
	"os"

	"github.com/unidoc/unioffice/v2/common/license"
	"github.com/unidoc/unioffice/v2/document"
	"github.com/unidoc/unioffice/v2/measurement"
	"github.com/unidoc/unioffice/v2/schema/soo/wml"
)


func init() {
    err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
    if err != nil {
        panic(err)
    }
}

func main() {
    doc := document.New()
    defer doc.Close()

    lorem := `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lobortis, lectus dictum feugiat tempus, sem neque finibus enim, sed eleifend sem nunc ac diam. Vestibulum tempus sagittis elementum.`// Single spaced paragraph

    para := doc.AddParagraph()
    run := para.AddRun()
    run.AddText(lorem)
    run.AddText(lorem)
    run.AddBreak()

    // Double spaced paragraph
    para = doc.AddParagraph()
    para.Properties().Spacing().SetLineSpacing(24*measurement.Point, wml.ST_LineSpacingRuleAuto)
    run = para.AddRun()

    run.AddText(lorem)
    run.AddText(lorem)
    run.AddBreak()

    if err := doc.Validate(); err != nil {
        log.Fatalf("error during validation: %s", err)
    }

    doc.SaveToFile("line-spacing.docx")
}

Step 3: Key Concepts Explained

1. Authentication

license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))

This line ensures your SDK usage is licensed properly.

You can get your API key from your UniCloud dashboard.

2. Creating a Document

doc := document.New()

This line initializes a new Word document.

All changes—spacing, text, styles—apply to this object.

3. Adding Paragraphs

para := doc.AddParagraph()

Here, you add a paragraph where the text will live.

Think of this as a container for your line space formatting.

4. Setting Single and Double Line Spacing

para.Properties().Spacing().SetLineSpacing(24*measurement.Point, wml.ST_LineSpacingRuleAuto)

This function adjusts the line spacing. The 24*measurement.Point value means double spacing, assuming a 12-point font.

To reduce line spacing, use a smaller number like 12*measurement.Point.

5. Final Output

doc.SaveToFile("line-spacing.docx")

Your file is saved and ready to use.

Open it in Word to see the effects of adjusted linespace.

Step 4: Run the Code

Execute the script to generate your document:

go run main.go

You’ll see a new file line-spacing.docx with both single and double spaced paragraphs.

Tips for Adjusting Line Spacing Effectively

Here are some practical suggestions when working with line space Word files:

Use Consistent Spacing

Avoid mixing line spacings unless for deliberate emphasis.

Don’t Use Enter for Spacing

Avoid pressing Enter multiple times to create space.

Always adjust paragraph or line space settings instead.

Use Styles When Possible

Apply predefined styles with built-in line spacing to speed up formatting.

Validate Output Programmatically

With UniOffice, always run:

doc.Validate()

This ensures your document is valid and won’t break on open.

When to Use Single vs. Double Spacing

SituationRecommended Line Spacing
Academic PapersDouble (2.0)
Business Reports1.15 or 1.5
Legal DocumentsDouble
Books & PublicationsSingle or 1.15
Resumes & Portfolios1.15

Knowing how to adjust line space in Word lets you match formatting to purpose.

Final Thoughts

Mastering line spacing gives you control over clarity, structure, and professionalism in your documents.

With this guide, you’ve learned:

  • How to change space between lines in Word

  • How to reduce or remove space between lines in Word

  • How to programmatically adjust linespace using UniOffice SDK