---
title: "PageWidth"
language: "en"
type: "Symbol"
summary: "PageWidth is an option for output streams and for cells that specifies how wide each line of text is allowed to be."
keywords: 
- breaking
- line length
- lines
- termcap
- width
- window
- window size
- wrapping
- text block
- textwrap
canonical_url: "https://reference.wolfram.com/language/ref/PageWidth.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Text Layout Options"
    link: "https://reference.wolfram.com/language/guide/TextLayoutOptions.en.md"
related_functions: 
  - 
    title: "TotalWidth"
    link: "https://reference.wolfram.com/language/ref/TotalWidth.en.md"
  - 
    title: "Alignment"
    link: "https://reference.wolfram.com/language/ref/Alignment.en.md"
  - 
    title: "TextJustification"
    link: "https://reference.wolfram.com/language/ref/TextJustification.en.md"
  - 
    title: "AutoIndent"
    link: "https://reference.wolfram.com/language/ref/AutoIndent.en.md"
  - 
    title: "InsertLinebreaks"
    link: "https://reference.wolfram.com/language/ref/InsertLinebreaks.en.md"
related_tutorials: 
  - 
    title: "Text and Font Options"
    link: "https://reference.wolfram.com/language/tutorial/ManipulatingNotebooks.en.md#21174"
  - 
    title: "Options for Notebooks"
    link: "https://reference.wolfram.com/language/tutorial/ManipulatingNotebooks.en.md#6483"
  - 
    title: "Files and Streams"
    link: "https://reference.wolfram.com/language/tutorial/FilesAndStreams.en.md"
  - 
    title: "Streams and Low‐Level Input and Output"
    link: "https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#21617"
---
# PageWidth
⚠ *Unsupported in Cloud*

PageWidth is an option for output streams and for cells that specifies how wide each line of text is allowed to be.

## Details

* Possible settings for output streams are:

|          |                                       |
| :------- | :------------------------------------ |
| Infinity | an infinite width (no line breaking)  |
| n        | explicit width in characters          |

* ``SetOptions[stream, PageWidth -> val]`` resets the line width allowed for an open stream.

* Possible settings for cells are:

|             |                                               |
| :---------- | :-------------------------------------------- |
| WindowWidth | the width of the window on the screen         |
| PaperWidth  | the width of the page as it would be printed  |
| n           | explicit width given in printer's points      |

* ``PageWidth -> WindowWidth`` allows each line to use the full width of the displayed window, taking into account settings for ``CellMargins``.

* The ``PageWidth`` setting of a cell sets the boundary for all of the cell's elements, including the ``CellMargins``, ``CellFrame`` and ``CellFrameLabels``. It does not include the space allocated for the cell bracket.

* ``PageWidth -> UpTo[n]`` is equivalent to the lesser of ``PageWidth -> WindowWidth`` and ``PageWidth -> n``.

* If the effective ``PageWidth`` is less than the window's width, the alignment of the contents of the cell is controlled by the ``Alignment`` option.

---

## Examples (9)

### Basic Examples (2)

Set the ``PageWidth`` to be 60 characters for a stream:

```wl
In[1]:= file1 = FileNameJoin[{$TemporaryDirectory, "test1"}];

In[2]:=
stream = OpenWrite[file1, PageWidth -> 60];
Write[stream, Expand[(x + y) ^ 5]];
Close[stream];
```

Set the ``PageWidth`` to be 30 characters for a stream:

```wl
In[3]:= file2 = FileNameJoin[{$TemporaryDirectory, "test2"}];

In[4]:=
stream = OpenWrite[file2, PageWidth -> 30];
Write[stream, Expand[(x + y) ^ 5]];
Close[stream];
```

Compare the two resulting files:

```wl
In[5]:= FilePrint[file1]

x^5 + 5*x^4*y + 10*x^3*y^2 + 10*x^2*y^3 + 5*x*y^4 + y^5

In[6]:= FilePrint[file2]

x^5 + 5*x^4*y + 10*x^3*y^2 + 
 10*x^2*y^3 + 5*x*y^4 + y^5
```

Delete the temporary files:

```wl
In[7]:= DeleteFile[{file1, file2}]
```

---

Create an Output cell with a fixed width:

```wl
In[1]:= CellPrint[TextCell["This is a bit of text", PageWidth -> 100, Background -> LightGreen]]
```

This is a bit of text

### Scope (4)

Set a fixed page width:

```wl
In[1]:= CellPrint[TextCell[StringTake[ExampleData[{"Text", "GettysburgAddress"}], 299], PageWidth -> 400]]
```

Four score and seven years ago, our fathers brought forth upon this continent a new nation: conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war...testing whether that nation, or any nation so conceived and so dedicated. . .

---

Set the width to use the full width of the window:

```wl
In[1]:= CellPrint[TextCell[StringTake[ExampleData[{"Text", "GettysburgAddress"}], 299], PageWidth -> WindowWidth]]
```

Four score and seven years ago, our fathers brought forth upon this continent a new nation: conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war...testing whether that nation, or any nation so conceived and so dedicated. . .

---

Set the width to the paper width for the default printer:

```wl
In[1]:= CellPrint[TextCell[StringTake[ExampleData[{"Text", "GettysburgAddress"}], 299], PageWidth -> PaperWidth]]
```

Four score and seven years ago, our fathers brought forth upon this continent a new nation: conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war...testing whether that nation, or any nation so conceived and so dedicated. . .

---

Set the width to be as much as 600 points, or narrower if the window is narrower:

```wl
In[1]:= CellPrint[TextCell[StringTake[ExampleData[{"Text", "GettysburgAddress"}], 299], PageWidth -> UpTo[600]]]
```

Four score and seven years ago, our fathers brought forth upon this continent a new nation: conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war...testing whether that nation, or any nation so conceived and so dedicated. . .

### Properties & Relations (3)

The ``PageWidth`` cell setting includes the horizontal space consumed by ``CellMargins`` :

```wl
In[1]:= Do[CellPrint[TextCell["This is a bit of text", PageWidth -> 400, CellMargins -> {{n, n}, {0, 0}}, Background -> LightGreen]], {n, 0, 150, 50}]
```

This is a bit of text

This is a bit of text

This is a bit of text

This is a bit of text

---

``PageWidth`` affects the width of ``CellFrame`` and the position of ``CellFrameLabels`` :

```wl
In[1]:= Do[CellPrint[TextCell["This is a bit of text", PageWidth -> n, CellFrame -> 1, CellFrameLabels -> {{"left", "right"}, {None, None}}]], {n, 200, 350, 50}]
```

This is a bit of text

This is a bit of text

This is a bit of text

This is a bit of text

---

``Alignment`` determines how cells affected by a narrow ``PageWidth`` align:

```wl
In[1]:= CellPrint[Cell["abc", PageWidth -> 200, CellFrame -> 1, Alignment -> Center]]
```

abc

## See Also

* [`TotalWidth`](https://reference.wolfram.com/language/ref/TotalWidth.en.md)
* [`Alignment`](https://reference.wolfram.com/language/ref/Alignment.en.md)
* [`TextJustification`](https://reference.wolfram.com/language/ref/TextJustification.en.md)
* [`AutoIndent`](https://reference.wolfram.com/language/ref/AutoIndent.en.md)
* [`InsertLinebreaks`](https://reference.wolfram.com/language/ref/InsertLinebreaks.en.md)

## Tech Notes

* [Text and Font Options](https://reference.wolfram.com/language/tutorial/ManipulatingNotebooks.en.md#21174)
* [Options for Notebooks](https://reference.wolfram.com/language/tutorial/ManipulatingNotebooks.en.md#6483)
* [Files and Streams](https://reference.wolfram.com/language/tutorial/FilesAndStreams.en.md)
* [Streams and Low‐Level Input and Output](https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#21617)

## Related Guides

* [Text Layout Options](https://reference.wolfram.com/language/guide/TextLayoutOptions.en.md)

## History

* Introduced in 1988 (1.0) \| Updated in 1996 (3.0) ▪ 2003 (5.0) ▪ [2020 (12.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn121.en.md)