12

I would like to put several lines of text stacked vertically inside a coffin, and have the coffin be the tightest rectangle containing them. One way to get a coffin containing those lines is to use \SetVerticalCoffin with an explicit width argument, but this doesn't make a tight coffin.

\documentclass{article}
\usepackage{xcoffins}
\begin{document}
\NewCoffin\Text
\SetVerticalCoffin\Text{12em}{\noindent%
  email@address.com\\%
  My postal address,\\%
  99999, BC, Canada%
}
\TypesetCoffin\Text
\end{document}

Another way is to build separate horizontal coffins and join them with the correct alignment, but that doesn't take care of proper line skips (even with the \strut inserted).

\documentclass{article}
\usepackage{xcoffins}
\begin{document}
\NewCoffin\Tmp
\NewCoffin\Text
\SetHorizontalCoffin\Tmp{\strut email@address.com}
\JoinCoffins\Text[b,l]\Tmp[t,l]
\SetHorizontalCoffin\Tmp{\strut My postal address,}
\JoinCoffins\Text[b,l]\Tmp[t,l]
\SetHorizontalCoffin\Tmp{\strut 99999, BC, Canada}
\JoinCoffins\Text[b,l]\Tmp[t,l]
\TypesetCoffin\Text
\end{document}

Neither approach is great. How do I get the coffin I want?

7
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Nah, just kidding :)
    – jub0bs
    Dec 11 '13 at 17:04
  • use an \halign and coffin-ize the resulting vbox? or are you really asking for a coffin function in place of join that aligns on the specified poles but offsets to preserve baselineskip? Dec 11 '13 at 17:05
  • 4
    @Jubobs Sorry, I forgot to say 'Helllllo gentle folks!' before and 'Thanks a lot if you help me!!! I'm loooost!' after my question. Dec 11 '13 at 17:13
  • @DavidCarlisle I guess the right approach would be to use a TeX's tables, but it's not clear to me how to get a coffin out of that without ever specifying a width. Perhaps \SetHorizontalCoffin\Text{\vbox{\halign{#\cr Foo\cr Bar\cr Baz\cr}}}? So I guess maybe I need a \SetVerticalCoffin variant which does not require a width argument (\vbox instead of \vbox to ...). Dec 11 '13 at 17:17
  • I hear that not apologising to a mule is a good way to get a coffin. I'm not sure if it's the one you want, though. Dec 11 '13 at 23:09
4

Using some ideas from my initial false attempts, I suggested using a \Longstack from the stackengine package. Here, I just stick it inside the horizontal coffin. The [l] optional argument left justifies the text in the stack. The interline spacing can be altered with \setstackgap{L}{length}. The \fbox demonstrates that it is the tightest coffin possible (but if you wanted the stack to be strutted, \strutlongstacks{T} in the preamble will see to that).

\documentclass{article}
\usepackage{xcoffins}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\NewCoffin\Text
\SetHorizontalCoffin\Text{%
\Longstack[l]{email@address.com\\My postal address\\99999, BC, Canada}%
}
\fboxsep=0pt
\fbox{\TypesetCoffin\Text}
\end{document}

enter image description here

In comments to the OP, egreg had suggested using tabular as a means to achieve the goal, and the OP asked for a compare/contrast on the two ideas. Indeed, one can take the macro line

\Longstack[l]{email@address.com\\My postal address\\99999, BC, Canada}%

and replace it with the environment

\begin{tabular}{l}
email@address.com\\My postal address\\99999, BC, Canada
\end{tabular}%

to achieve a similar result at the expense of a few extra keystrokes. Both methods can control the inter-row spacing with settable parameters. HOWEVER, there are differences in these two results. The tabular result is padded both on the left/right as well as the top/bottom. The left/right padding can be removed with the extra step of setting \tabcolsep=0pt. I am not exactly sure how to remove the top/bottom padding off of a tabular, other than setting \arraystretch to 0, but that, of course destroys the inter-row spacing, as well. Perhaps someone can comment on how that part is done.

Those are the differences that pop out to me. I don't know if the baseline of the object stuffed into a coffin affects the coffin behavior. However, both tabular and stackengine can control their respective baselines, so that shouldn't be an issue, per se. If I knew more about coffins, there may be other things that come to mind.

Of course, tabular is built into LaTeX, whereas stackengine is an extra package.

3
  • Bruno means one of these river-valley.zeeba.tv/exhuming-coffins-from-the-last-century Dec 11 '13 at 17:58
  • This does look like a good use case for the stackengine package. For completeness, could you comment on the advantage/drawback of using \Longstack[l]{...} rather than \begin{tabular}{l}...\end{tabular}? (Probably \Longstack is more efficient at least for small tables... but most definitely that does not matter since coffins are much slower.) Dec 12 '13 at 15:46
  • Thank you. Accepted. I think the \Longstack approach is most practical in this case. Dec 12 '13 at 17:10

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.