I have seen the command \shortstack in some nodes in TikZ (for example, the accepted answer here).

What is used for? I couldn't find its definition in the TikZ manual.


\shortstack is not part of tikz. It is used to stack items over each other. Note that the MWE does not use any packages.

enter image description here


\shortstack[alignment]{line 1 \\ line 2 \\ line 3 etc. }

where the valid alignement are:

r - right aligned
l - left aligned
c - centered (default)




\shortstack is not a tikz-specific command. It is part of the standard LaTeX distribution and is defined in latex.ltx with the following format:


Here is the original definition(s):

    \baselineskip-\p@\lineskip 3\p@
    \expandafter\let\csname mb@#1\endcsname\relax
\gdef\@ishortstack#1{\ialign{\mb@l {##}\unskip\mb@r\cr #1\crcr}\egroup}

It is meant to stack things on top of one another like in a tabular. However, it has a shorter \baselineskip, causing a shorter vertical stacking of elements.

Here is a minimal example showing some of the difference between tabular and \shortstack:

enter image description here

  \verb|\shortstack|: & \shortstack{Predefined\\Process} \hspace{1cm}
    \shortstack[r]{Predefined\\Process} \hspace{1cm}
    \shortstack[l]{Predefined\\Process} \\ \hline
  \verb|tabular|: & \begin{tabular}{@{}c@{}}Predefined\\Process\end{tabular} \hspace{1cm}
    \begin{tabular}{@{}r@{}}Predefined\\Process\end{tabular} \hspace{1cm}

Note the reduced baseline skip in \shortstack. Also, \shortstack necessarily has a zero-width horizontal padding. Finally, the default alignment for \shortstack is along the baseline, while tabular allows for top, center (default), or baseline.


\shortstack is defined in the basic latex.ltx file. its purpose is to set text in multiple lines within a confined area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.