1

I would like to solve the following problem.

I would like to include some multiline content (within a box, a minipage or anything else) within a text so that the text is aligned to the top line (of the boxed content) from the left and to the bottom line from the right.

Any suggestion on how to do this would be appreciated.

2 Answers2

1

You mean like this?

This is a
part of the
surrounding  +---------+
text.        |This is  |
             |the boxed|
             |content. | Here the surrounding
             +---------+ text continues.

If yes, this can be achieved with the following:

\splittopskip=\ht\strutbox
\setbox0=\vbox{\hsize=6em\leftskip=2pt\rightskip=\leftskip
\penalty0 %first \vsplit here
\noindent\strut This is the boxed con\-tent.\strut\par}
\hbox to\hsize{%
 \vbox{\hsize=6em
 This is a part of the surrounding text.\par}%
 \kern6pt
 \setbox1=\vsplit0 to0pt %insert \splittopskip at the top of \box0
 \hbox{\vrule\vbox{\hrule\kern-.4pt\vsplit0 to\ht\strutbox}\vrule}
 \hfil
}\nointerlineskip
\hbox to\hsize{%
 \kern6em
 \kern6pt
 \dimen1=\dp0 \setbox1=\vbox{\box0 \kern-.4pt\hrule}\dp1=\dimen1
  \multiply\dimen1 by-1\advance\dimen1 by\ht1 \ht1=\dimen1
  \hbox{\vrule\box1 \vrule}
 \kern6pt
 \vtop{\hsize=6em
 \noindent Here the surrounding text continues.\par}%
 \hfil
}

enter image description here

But this solution (which reuses some ideas from Having two right brackets with alignat) assumes that the surrounding text does not use the full page width, and there is also no page-breaking.

1

I'm not sure if this is what you want. The baseline of the first line of a minipage is to be aligned with the preceding text, but the last line of the minipage is to be aligned with the text that follows.

This is accomplished using the package tikzpagenodes, which has a built-in node called current page text area. So after the preceding text, we construct a path (not drawn) from the end of the current line to the left text area.

Then a new paragraph starts with that path from to properly indent a minipage, which has the [b] option to align its last line with the text that follows. The minipage is shifted up to align with the previous line of text.

This is all wrapped into a macro called that takes two arguments:

\tbminipage{<width>}{<content>}

You have to compile this twice.

enter image description here

\documentclass{article}

\usepackage{tikzpagenodes}

\newcommand{\tbminipage}[2]{\tikz[remember picture,overlay] {\coordinate(a)at(0,0);\path (a) to (a-|current page text area.west);} \par\vspace{-.66\baselineskip}\noindent\tikz{\path (a) to (a-|current page text area.west);}% \begin{minipage}[b]{#1}#2\end{minipage}}

\begin{document}

This is the text that comes before. This is the text that comes before. This is the text that comes before. This is the text that comes before. This is the text that comes before. This is the text that comes before. This is the text that comes before. \tbminipage{2.5in}{This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle. This is the text in the middle.} This is the text that comes after. This is the text that comes after. This is the text that comes after. This is the text that comes after. This is the text that comes after. This is the text that comes after.

\end{document}

Sandy G
  • 42,558