# Environment to replace \vbox{\hbox{…}\hbox{…}\hbox{…}\hbox{…}…}

I am using LaTeX (LuaLaTeX,actually) and lately I found myself doing this a lot:

\vbox{%
\hbox{\strut foo}%
\hbox{\strut bar}%
\hbox{\strut baz}%
}


I use it inside tabular environments, floats, on title pages and sometimes even in normal text. When I do this foo, bar and baz are always a lot shorter than, e.g. \linewidth. I found this to be the easiest and quickest thing to get what I want. On special occasions, when there are a lot of items to display I resort to \tabular{l}.

Both constructs look like this is not how LaTeX is supposed to work from an user's perspective. Is there some environment or anything I can use to achieve the same effect as my 5 lines above do? Of course there are for example all the itemizes, but those all have some margin/padding/indent magic about them that always ends up making me want to use Word. My \vbox-\hbox-\strut construct works always as expected, in 100% of my use cases.

• \halign{\strut#\crcr foo\cr bar\cr baz\cr} (You can even leave out \strut) – Henri Menke May 31 '16 at 12:20
• \def\shortycut#1#2#3{\vbox{% \hbox{\strut #1}% \hbox{\strut #2}% \hbox{\strut #3}% } causes an error? – MaestroGlanz May 31 '16 at 12:21

Maybe some variety of "long" (rows at fixed baselineskip value) stack would suit your needs.

\documentclass{article}
\usepackage{stackengine}
\setstackEOL{$} \setstackgap{L}{\normalbaselineskip} \strutlongstacks{T} \begin{document} \begin{tabular}{|l|l|} \hline \Longstack[l]{foo$  bar$baz} & text\\ \hline \Centerstack[l]{foo$  bar$baz} & text\\ \hline \Longunderstack[l]{foo$  bar\$  baz} & text\\
\hline
\end{tabular}
\end{document}


• This is the first time I come across stackengine. This looks awesome. especially with the long center and longunder variants for tabular environments! – Bananguin May 31 '16 at 12:33
• @user1129682 Thanks. As it is my package, let me know if you have any questions on its use. – Steven B. Segletes May 31 '16 at 12:42

If you want to write your current construct much shorter, use \halign (and consider using plain TeX).

\documentclass{article}
\begin{document}
\halign{#\crcr foo\cr bar\cr baz\cr}
\end{document}


• Does \halign fall under the category of tex primitives we are not supposed to use (like hbox and vbox)? – Bananguin May 31 '16 at 12:36
• \halign is a TeX primitive, but I have never heard that you are not supposed to use any TeX primitives. It is perfectly safe to use and well documented in the TeXbook. – Henri Menke May 31 '16 at 12:44
\input expl3-generic

\ExplSyntaxOn

\cs_new_protected:Npn \vboxofhboxes #1
{
\vbox:n
{
\clist_map_inline:nn { #1 }
{
\hbox:n { \strut ##1 }
}
}
}

\ExplSyntaxOff

\vboxofhboxes{
foo,
bar,
baz,
OK
}

\bye


I can't really see the advantage over

\begin{tabular}{@{}l@{}}
foo \\
bar \\
baz
\end{tabular}


or similar Plain TeX construction.

• What is this expl3 sorcery? It looks like a lot of libraries to include which will make the build process very time consuming. The advantage would be that \vboxofhboxes adds a lot less clutter to my documents and of course I can redefine \vboxofhboxes once to add fancy layout everywhere, if I wanted to. – Bananguin May 31 '16 at 12:40
• @user1129682 Time consuming? Not at all, just a couple of seconds, perhaps. On the other hand, it provides for very compact code. – egreg May 31 '16 at 18:15