3

How can I force \shortstack to preserve an empty line? For example,

\shortstack[c]{hoge \\ foo \\ bar}
\shortstack[c]{hoge \\  \\ bar}

provides preview

. But I would like to keep the empty line in the middle.

  • Do you need to use \shortstack? Why not just a tabular (which will preserve line heights and empty rows)? – Werner Jan 24 '17 at 20:22
2

\shortstack is really unsuitable for uniformly stacking characters, because it just takes into account the character's height and depth, adding just 3pt between them.

Look at the result with

\documentclass{article}

\begin{document}

\shortstack{a\\c\\e}
\shortstack{g\\y\\q}
\shortstack{fg\\ly\\pt}
\shortstack{l\\a\\f}

\end{document}

enter image description here

The result is surely not what you expected it to be. The command is only useful when its argument consists of capital letters only (without diacritics).

\documentclass{article}

\newcommand{\bettershortstack}[2][c]{%
  \begin{tabular}[b]{@{}#1@{}}#2\end{tabular}%
}

\begin{document}

\bettershortstack{a\\c\\e}
\bettershortstack{g\\y\\q}
\bettershortstack{fg\\ly\\pt}
\bettershortstack{l\\a\\f}

\end{document}

enter image description here

And now your example:

\documentclass{article}

\newcommand{\bettershortstack}[2][c]{%
  \begin{tabular}[b]{@{}#1@{}}#2\end{tabular}%
}

\begin{document}

\bettershortstack{hoge \\ foo \\ bar}
\bettershortstack{hoge \\  \\ bar}

\end{document}

enter image description here

| improve this answer | |
0

For things to line up properly, use a \vphantom, since line heights are relative to the entry:

enter image description here

\documentclass{article}

\usepackage{stackengine}

\begin{document}

\shortstack[c]{hoge \\ foo \\ bar}
\shortstack[c]{hoge \\  \\ bar}
\shortstack[c]{hoge \\ \vphantom{foo} \\ bar}

\end{document}
| improve this answer | |

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.