2

I want to obtain a certain layout, illustrated below: at some point in a line, I'd like to "switch to paragraph mode" (just like a parbox does) and then at some other point I want to resume back to normal full-width typesetting. In my case, the idea is to get a ToC-like look using dotfill, but the question stands for regular text too, I suppose.

Using the xcoffins package I got this partial solution (MNWE below) which is neither very elegant in terms of code nor correct-looking in terms of result:

result

My questions (illustrated with arrows in the picture above):

  1. Is this the right™ way to do it ?
  2. I want the "dot filling" to go all the way to the right margin. Using two \dotfill commands somehow works, but the result doesn't look quite right (cf picture, there is extra space between the two dotfills). Is there a way out of this ?
  3. How do I fix the wrong interline spacing below the coffin ? In the "central column" I'd like all lines to be equally spread apart.
  4. Is there a more elegant way to horizontally join two coffins with adjacent text ? Here I'm joining bol and para with an explicit .5ex spacing and this feels wrong (even though it looks OK).

.

\documentclass{minimal}

\setlength{\parindent}{0pt}

\usepackage{xcoffins}

\begin{document}

\NewCoffin\cont% full-width container
\NewCoffin\para% multiline paragraph
\NewCoffin\bol % beginning of line 
\NewCoffin\eol % end of line

\SetVerticalCoffin\cont{\linewidth}{~}

\SetHorizontalCoffin\bol{In-coffin beginning of line.}

\SetVerticalCoffin\para{15 em}{Dummy text but long enough to span several lines at the specified width\dotfill}

\JoinCoffins \bol[B,r] \para[T,l](.5ex, 0pt)

\JoinCoffins \cont[B,l] \bol

\SetVerticalCoffin \eol {\CoffinWidth\cont - \CoffinWidth\bol}{\dotfill\rule{1ex}{1ex}}

\JoinCoffins \cont[\para-B,\para-r] \eol

A long chunk of text to show how the thing flows with surrounding lines. 
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.

\TypesetCoffin\cont

A long chunk of text to show how the thing flows with surrounding lines. 
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.


\end{document}
6
  • Please don't use minimal for examples. It isn't suitable.
    – cfr
    Commented May 27, 2016 at 23:55
  • B isn't supposed to exist for horizontal coffins - only vertical ones.
    – cfr
    Commented May 28, 2016 at 0:24
  • Though they seem to be defined, even so.
    – cfr
    Commented May 28, 2016 at 0:30
  • There is something really weird about this ... :(.
    – cfr
    Commented May 28, 2016 at 1:27
  • 1
    Please see tex.stackexchange.com/questions/42114/…. article would be perfect here. For graphics (e.g. TikZ pictures) standalone is a popular option, but for other things, article would be recommended. (Unless the issue specifically concerns Memoir or something, obviously, as then you'd need that class.)
    – cfr
    Commented May 30, 2016 at 12:55

2 Answers 2

1

Here are two minor adjustments to your MWE which produce the desired result.

The first adjustment is to nudge the \eol coffin a bit to the left when joining it to the \cont coffin. .22em is one half of the space which \dotfill uses for a box containing an individual dot. Tweak this as desired. Although the gap is less visible now, you might need a slightly larger adjustment for a perfect match.

\JoinCoffins \cont[\para-B,\para-r] \eol (-.22em,0pt)

The second adjustment involves adding \strut to the final line of \para. I have no idea why this is necessary as I don't know why the use of coffins (either the underlying expl3 functions or xcoffins) loses vertical spacing here.

\SetVerticalCoffin\para{15 em}{Dummy text but long enough to span several lines at the specified width \strut\dotfill}

Here's the result:

output from modified code

Complete code:

\documentclass{article}
\setlength{\parindent}{0pt}

\usepackage{xcoffins}

\begin{document}

\NewCoffin\cont% full-width container
\NewCoffin\para% multiline paragraph
\NewCoffin\bol % beginning of line
\NewCoffin\eol % end of line

\SetVerticalCoffin\cont{\linewidth}{~}

\SetHorizontalCoffin\bol{In-coffin beginning of line.}

\SetVerticalCoffin\para{15 em}{Dummy text but long enough to span several lines at the specified width \strut\dotfill}

\JoinCoffins \bol[B,r] \para[T,l](.5ex, 0pt)

\JoinCoffins \cont[B,l] \bol

\SetVerticalCoffin \eol {\CoffinWidth\cont - \CoffinWidth\bol}{\dotfill\rule{1ex}{1ex}}

\JoinCoffins \cont[\para-B,\para-r] \eol (-.22em,0pt)

A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.

\TypesetCoffin\cont

A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.


\end{document}
2
  • The 0.5ex and -0.22em still need to be adjusted manually when font size varies, but this workaround fixes most of my problems, cheers !
    – Gyom
    Commented Jun 3, 2016 at 8:25
  • 1
    @Gyom That's true but, at least for the \dotfill, I don't see much way around it since the command just prints a series of boxes of width .44em with a dot in the middle of each, basically. Probably really you should trace through what happens specifically at the start of \dotfill, but I couldn't figure it out and thought a workaround better than nothing at all when nobody else answered in terms of coffins. Perhaps somebody else will see this and post a better solution all round. I hope so!
    – cfr
    Commented Jun 3, 2016 at 15:37
2

You can do it without coffins:

\documentclass{article}

\newenvironment{almostcenter}
 {\par\nobreak
  \leftskip=\dimexpr(\textwidth-15em)/2\relax
  \rightskip=\leftskip
  \parfillskip=-\rightskip
  \noindent\ignorespaces}
 {\unskip\dotfill\par\noindent\ignorespacesafterend}


\begin{document}

A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
\begin{almostcenter}
Dummy text but long enough to span several lines at the specified width
\end{almostcenter}
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.
A long chunk of text to show how the thing flows with surrounding lines.

\end{document}

enter image description here

5
  • Doesn't the OP want the first line of the Dummy text ... aligned with the last line preceding it on the baseline?
    – cfr
    Commented May 27, 2016 at 23:59
  • @cfr Possibly; that requires the usual tricks with measuring the positions. I don't think one can dispense with them, for this application.
    – egreg
    Commented May 28, 2016 at 7:09
  • @egreg thanks for your answer. So much voodoo though. Would you have any suggestions as to where I could learn about these leftskip, dimexpr, relax etc ? Cheers.
    – Gyom
    Commented May 30, 2016 at 7:51
  • 1
    @Gyom Not too much voodoo, actually; \leftskip and \rightskip is space at the left and right of lines; \parfillskip is the space automatically added at paragraph end, by setting it equal to the negative of \rightskip we obtain that the leaders are flush with the right margin. For \dimexpr search on the site, you'll find many examples.
    – egreg
    Commented May 30, 2016 at 7:56
  • Why doesn't the OP's code work?
    – cfr
    Commented Jun 1, 2016 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .