4

Consider the following Minimal Working Example (MWE):

\documentclass{article}
\usepackage{xcoffins,kantlipsum}
\begin{document}
\NewCoffin \MyCoffin
\NewCoffin \YourCoffin
\SetVerticalCoffin \MyCoffin {.75\linewidth}
{%
  \kant[1]
}
\SetVerticalCoffin \YourCoffin {.75\linewidth}
{%
  \kant[2]
}
\JoinCoffins \MyCoffin [b,l] \YourCoffin [t,l]
\TypesetCoffin \MyCoffin
\end{document}

If you prefer the expl3 syntax, here's the same example using the underlying functions rather than the xcoffins interface:

\documentclass{article}
\usepackage{expl3,kantlipsum}
\begin{document}
\ExplSyntaxOn
\coffin_new:N \l_exp_my_coffin
\coffin_new:N \l_exp_your_coffin
\vcoffin_set:Nnn \l_exp_my_coffin {.75\linewidth}
{
  \kant[1]
}
\vcoffin_set:Nnn \l_exp_your_coffin  {.75\linewidth}
{
  \kant[2]
}
\coffin_join:NnnNnnnn \l_exp_my_coffin { b } { l } \l_exp_your_coffin { t } { l } { 0pt } { 0pt }
\coffin_typeset:Nnnnn \l_exp_my_coffin { b } { l } { 0pt } { 0pt }
\ExplSyntaxOff
\end{document}

Either way, the result is

squished coffins

which is obviously not ideal. Ideally, the result would be similar to the result of typesetting the contents of both coffins in a single coffin.

\SetVerticalCoffin \MyCoffin {.75\linewidth}
{%
  \kant[1-2]
}
\TypesetCoffin \MyCoffin

non-squished lone coffin

Obviously there are ways to work around this problem. The following list of such methods is intended to be indicative rather than exhaustive.

  1. Include explicit vertical spacing as content at the end of \MyCoffin.
  2. Include explicit vertical spacing as content at the start of \YourCoffin.
  3. Use the offset option of \JoinCoffins to adjust the point at which \YourCoffin is joined to \MyCoffin.

For example

\SetVerticalCoffin \MyCoffin {.75\linewidth}
{%
  \kant[1]
}
\SetVerticalCoffin \YourCoffin {.75\linewidth}
{%
  \kant[2]
}
\JoinCoffins\MyCoffin[b,l]\YourCoffin[t,l](0pt,-.2\baselineskip-\parskip)
\TypesetCoffin \MyCoffin

approximates the correct result.

almost correct?

However, not only is this not quite right, it is inflexible and fiddly. Moreover, it seems rather alien to the whole concept of coffins and their approach. At best, it is inelegant: it re-complicates something which the idea of a coffin was, I think, trying to simplify.

That is, I'm certain this cannot be how I'm supposed to do this.

What is the correct way to stack two coffins so that the vertical spacing between their contents is more-or-less what it would be if the content of both was simply set in a single coffin?

Note that a solution need not use the xcoffins interface. I'm really interested in the expl3 layer and have only translated to the higher-level macros to simplify presentation of the question.

2
  • I think this is a problem with \prevdepth. Search this site about \prevdepth with minipages. May be this should be implemented “officially”?
    – Manuel
    Jun 5 '16 at 22:52
  • 2
    @Manuel yes but minipages only have one reference point which is why it's a problem with minipages, and why coffins have more than one reference point. Jun 5 '16 at 23:13
6

Coffins were really invented to address this, you want a baselineskip offset between the pole along the bottom baseline of the first coffin and the top baseline of the second

enter image description here

\documentclass{article}
\usepackage{expl3,kantlipsum}
\begin{document}
\ExplSyntaxOn
\coffin_new:N \l_exp_my_coffin
\coffin_new:N \l_exp_your_coffin
\vcoffin_set:Nnn \l_exp_my_coffin {.75\linewidth}
{
  \kant[1]
}
\vcoffin_set:Nnn \l_exp_your_coffin  {.75\linewidth}
{
  \kant[2]
}
\coffin_join:NnnNnnnn \l_exp_my_coffin { B } { l } \l_exp_your_coffin { T } { l } { 0pt } { -\baselineskip }
\coffin_typeset:Nnnnn \l_exp_my_coffin { b } { l } { 0pt } { 0pt }
\ExplSyntaxOff
\end{document}
14
  • Aha! That makes much more sense, Thank you. I should have thought of this ... ;).
    – cfr
    Jun 5 '16 at 23:05
  • Is there a use case for three vertically aligned coffins? In case it's true, how would one solve that?
    – Manuel
    Jun 5 '16 at 23:09
  • 2
    @cfr note that this assumes that it's possible to have just baselineskip space here, if there is extra deep material in the first or high in the second, it'll overprint, but probably the coffin way is to adjust the poles in that case before joining rather than just taking the standard T and B (to emulate \lineskip you would in that case drop back to t and b` and offset by \lineskip rather than \baselineskip but that never looks good really Jun 5 '16 at 23:09
  • @Manuel Why would that be a problem?
    – cfr
    Jun 5 '16 at 23:10
  • 2
    @Manuel not sure I understand the question, a coffin can have any number of poles so when you join two of them you can set up the poles on that, and then attach the third referencing the poles? Jun 5 '16 at 23:11
2

You can add struts

\documentclass{article}
\usepackage{xcoffins,kantlipsum}
\begin{document}
\footnotesize\parindent=0pt

\NewCoffin \MyCoffin
\NewCoffin \YourCoffin
\SetVerticalCoffin \MyCoffin {.5\linewidth}
{%
  \strut\kant*[1]\strut
}
\SetVerticalCoffin \YourCoffin {.5\linewidth}
{%
  \strut\kant*[2]\strut
}
\hrule
\JoinCoffins \MyCoffin [b,l] \YourCoffin [t,l]
\TypesetCoffin \MyCoffin
\parbox{0.5\linewidth}{\kant[1-2]}
\hrule
\end{document}

enter image description here

2
  • 1
    Thanks, yes. I thought of including this in my list but decided that a full list of workarounds would not be to the point. Or is this the correct way and not just a workaround?
    – cfr
    Jun 5 '16 at 22:59
  • Of course every solution works as long the font size inside the coffins (the same for both) coincides with the font size of the main document. Oct 25 '19 at 21:33

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.