# \shortstack when writing text in nodes in TikZ

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.

-

## 3 Answers

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

## Syntax:

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


where the valid alignement are:

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


## Code:

\documentclass{article}

\begin{document}
\shortstack{Predefined\\Process}
\hspace{1cm}
\shortstack[r]{Predefined\\Process}
\hspace{1cm}
\shortstack[l]{Predefined\\Process}
\end{document}

-

\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:

\shortstack[<alignment>]{<stuff>}


Here is the original definition(s):

\gdef\shortstack{\@ifnextchar[\@shortstack{\@shortstack[c]}}
\gdef\@shortstack[#1]{%
\leavevmode
\vbox\bgroup
\baselineskip-\p@\lineskip 3\p@
\let\mb@l\hss\let\mb@r\hss
\expandafter\let\csname mb@#1\endcsname\relax
\let\\\@stackcr
\@ishortstack}
\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:

\documentclass{article}
\begin{document}
\begin{tabular}{ll}
\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}
\begin{tabular}{@{}l@{}}Predefined\\Process\end{tabular}
\end{tabular}
\end{document}​


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.

-