How to Change Cell Width in tikz-cd
At a glance
- 1. Choose the cell
Put node options between vertical bars at the start of the tikz-cd cell.
- 2. Set a minimum width
Use minimum width to make that cell, and therefore its column, at least as wide as needed.
- 3. Adjust the gap separately
Use column sep to change spacing between columns; it does not set a cell's width.
In tikz-cd, each entry in the diagram is a TikZ node arranged in a matrix. To make one entry wider, give that node a width option at the start of its cell. The simplest option is minimum width.
This changes the node’s size, not just the space around the diagram. Since a matrix column must fit its widest cell, widening one cell can also widen the column in every row.
Set the width of one cell
Place the node options between |[ and ]| before the cell contents:
|[minimum width=4cm]| B
Here is a complete example:
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[column sep=1em]
A \arrow[r] & |[minimum width=4cm]| B \arrow[r] & C
\end{tikzcd}
\]
\end{document}
The second cell is made at least 4 cm wide. The first and third columns are not given that minimum width. The arrows still connect to the nodes as usual; TikZ adjusts their endpoints to the nodes’ edges.
minimum width means the node’s total width is at least the stated value. If the contents plus TikZ’s inner padding require more room, the node can be wider; the padding is included in the node’s dimensions, not added on top of the minimum width.
Make room for longer contents
For a cell that contains a long formula, increasing its minimum width can prevent nearby columns from crowding it. For example:
\begin{tikzcd}
X \arrow[r] & |[minimum width=5cm]| f^{*}(Y) \arrow[r] & Z
\end{tikzcd}
The option belongs to the cell that follows it. If the cell is in another row, add the option to that cell as well if you want the whole column to have a consistent minimum width. The column’s final width is determined by its widest cell.
A fixed text width is another node option, useful when you want ordinary text to wrap within a specified text area. For example, |[text width=3cm,align=center]| sets a text area and centers its lines. In a tikz-cd diagram, cell contents are commonly mathematical material; a displayed formula does not automatically wrap like a paragraph. Choose a width option that fits the kind of contents you have.
Cell width versus column spacing
If the issue is that two columns are too close together, adjust column sep instead:
\begin{tikzcd}[column sep=3em]
A \arrow[r] & B
\end{tikzcd}
This increases the separation between columns. It does not give a particular cell a minimum width. Use row sep similarly to change the distance between rows. A diagram may need both a wider cell and a larger column separation, but those options solve different problems.
| Goal | Use |
|---|---|
| Make one node at least a given width | ` |
| Give a node a text area that can wrap text | ` |
| Increase the gap between columns | column sep=... |
| Increase the gap between rows | row sep=... |
Common mistakes
- Changing
column sepwhen the cell itself is too narrow. This moves columns farther apart but does not set the node’s width. - Expecting
minimum widthto force an exact width. It sets a lower bound. Contents or padding can make the node wider. - Applying the option to the wrong cell. The
|[... ]|options apply to the cell immediately following them, so put them after the correct&separator. - Expecting a long mathematical expression to wrap automatically. A width option does not necessarily break a formula at a suitable point. For complicated formulas, add a deliberate line break using a suitable math construction, or redesign the diagram layout.
- Forgetting that cells share a column. One wide node can make that whole column wider, affecting the apparent spacing of the diagram.
If you only need extra visual space around a diagram, adjust column sep. If you need a node itself to occupy more width, set a node option on that cell.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.