Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 9 down vote accepted

\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

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}
share|improve this answer

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

enter image description here

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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