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.

cfr
  • 198,882
  • I think this is a problem with \prevdepth. Search this site about \prevdepth with minipages. May be this should be implemented “officially”? – Manuel Jun 05 '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. – David Carlisle Jun 05 '16 at 23:13

2 Answers2

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}
David Carlisle
  • 757,742
  • Aha! That makes much more sense, Thank you. I should have thought of this ... ;). – cfr Jun 05 '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 05 '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 band offset by\lineskiprather than\baselineskip` but that never looks good really – David Carlisle Jun 05 '16 at 23:09
  • @Manuel Why would that be a problem? – cfr Jun 05 '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? – David Carlisle Jun 05 '16 at 23:11
  • Yes, but then you're dealing with what I'd consider in some sense non-standard content. I thought there must be a straightforward answer for the standard case, so to speak. I'm not surprised if there's no off-the-shelf solution for special cases, if that makes sense. – cfr Jun 05 '16 at 23:11
  • @DavidCarlisle And you don't need non-standard poles, do you? If they are all vertical coffins, you can use B from the combo coffin, from the lower inner coffin, and T from the new coffin? – cfr Jun 05 '16 at 23:13
  • @cfr if I understand Manuel's question, yes that's right. with a minipage you have to choose [t] (which is like coffin T) or [b] (like B) which means the middle of three minipages is usually difficult to space correctly at the top or the bottom. the initial idea of coffins was to have access to both the top and bottom baseline for exactly this use. – David Carlisle Jun 05 '16 at 23:16
  • @DavidCarlisle That was my doubt, I don't know how coffins work, so it was a question thinking in minipages. – Manuel Jun 05 '16 at 23:18
  • @Manuel a coffin is like a box, but since dead people are heavy they have multiple handles:-) – David Carlisle Jun 05 '16 at 23:20
  • @DavidCarlisle Could I avoid using \strut in this answer? (Or the hard-coding of the horizontal spaces - but I don't think that's a coffins thing.) – cfr Jun 05 '16 at 23:25
  • It gets tricky to use this if one of the coffins is the result of a previous join, right? It seems to lose track of where the correct baseline is, even if the material doesn't contain anything by standard height text? – cfr Jun 06 '16 at 13:12
  • @cfr I'll have to look later at the current state of the code (I answered above based on a recollection from 1995 or something:-) or perhaps Joseph might pass by.... You should be able to set a pole on the join to be the B pole of one of its components, then use that to attach to the T pole of the next... – David Carlisle Jun 06 '16 at 13:20
  • What's confusing me in the answer I linked is that I need to make it work relative to text above and below the final, typeset coffin. Without \strut, I can get the space either above or below to look about right. But I can't get both even approximately right. I figure there must be some combination of pole choice and offset when typesetting the coffin which should make it work correctly, but I can't figure out what it is. – cfr Jun 07 '16 at 00:19
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

egreg
  • 1,121,712
  • 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 05 '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. – Simon Dispa Oct 25 '19 at 21:33