Tx · LaTeX & TikZ

How to Change Line Spacing in a Shortstack-Like Box

Published By the 9to5Science editorial team

At a glance

  1. 1. Use a Tabular Box

    Replace \shortstack with a one-column tabular environment for adjustable row spacing.

  2. 2. Set the Spacing

    Change \arraystretch locally to scale the spacing between rows.

  3. 3. Tune One Break

    Add an optional length after a row break when only one gap needs adjustment.

The standard \shortstack is convenient for putting centered lines in a small box, but it offers limited control over the distance between those lines. A one-column tabular gives you more control while still producing a compact box that can sit in running text.

For general text, make the box with \begin{tabular}{c}...\end{tabular}. To adjust the spacing without affecting other tables, change \arraystretch inside a group around that tabular.

A reusable shortstack-like command

This command accepts an optional spacing factor. Its default, 1, uses the usual tabular row spacing; a larger value increases the row height, and a smaller value decreases it.

\documentclass{article}

\newcommand{\flexshortstack}[2][1]{%
  \begingroup
  \renewcommand{\arraystretch}{#1}%
  \begin{tabular}[c]{@{}c@{}}#2\end{tabular}%
  \endgroup
}

\begin{document}

Default spacing: \flexshortstack{First line\\Second line}.

More spacing: \flexshortstack[1.5]{First line\\Second line}.

A specific extra gap:
\begin{tabular}[c]{@{}c@{}}
  First line\\[4pt]
  Second line
\end{tabular}.

\end{document}

The optional [c] on tabular vertically centers the box with respect to the surrounding baseline. The c in the column specification centers the text horizontally, matching the default horizontal alignment of \shortstack. The @{}...@{} removes the tabular’s usual left and right padding, so the result is a close fit around the text. The group keeps the \arraystretch change local to this box.

Choose a spacing method

Use \arraystretch when you want to scale the spacing throughout the stack. For example, \flexshortstack[1.5]{A\\B\\C} makes the rows taller than the default. It is a scaling factor, not a measurement in points, and it changes the row heights rather than specifying an exact baseline-to-baseline distance.

If you want to add a fixed amount at just one break, use the optional length on the tabular row break: \\[4pt] adds 4 points after that row. This is useful when only one pair of lines needs extra separation.

Using the box in math mode

tabular is a text-mode environment. If the stacked material belongs inside a mathematical expression, use array instead. For example:

\[
  \renewcommand{\arraystretch}{1.4}
  \begin{array}{c}
    x+y\\
    z+w
  \end{array}
\]

For a reusable math-mode command, define a similar wrapper around array and keep the \arraystretch change local. Do not place a tabular directly inside math mode; use array or wrap text content in \text{...} when appropriate.

Common mistakes

  • Changing \arraystretch globally: A redefinition outside a group can affect later tables. Keep it inside braces or a group when the change is only for one box.
  • Treating the factor as a point value: \arraystretch scales row spacing; it does not mean “add this many points.” Use the row-break length for a specific fixed gap.
  • Using the wrong environment: tabular is for text mode, while array is for math mode.
  • Expecting identical dimensions to \shortstack: The contents and alignment can match closely, but tabular row struts and spacing rules differ. Adjust the factor to suit the surrounding text.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.