答案1
您可以通过在第一行添加前面的文本来\phantom
伪造它:\llap
\leavevmode\hbox{\phantom{before }\vbox{% this gets me bottom alginment, \vtop gets me top alginment, I want "both"
\hbox{\llap{before }the main text}
\hbox{that has several lines}
\hbox{of unknown width}
}}
after
\bye
如果您接受使用expl3
,您还可以使用其强大的棺材概念:
\input expl3-generic\relax
\newdimen\linewidth
\newdimen\columnwidth
\ExplSyntaxOn
\cs_new:Npn \myalign #1 #2 #3 {
\group_begin:
\hcoffin_set:Nn \l_tmpa_coffin {#1}
\vcoffin_set:Nnn \l_tmpb_coffin {\vsize} {#2}
% The *r*ight end of the before text should be *l*eft of the *t*op line:
\coffin_join:NnnNnnnn
\l_tmpb_coffin {l} {T}
\l_tmpa_coffin {r} {H}
{-3.33pt} {0pt}
\hcoffin_set:Nn\l_tmpa_coffin{#3}
% The *l*ight end of the after text should be *t*eft of the *b*ase line:
\coffin_join:NnnNnnnn
\l_tmpb_coffin{r}{B}
\l_tmpa_coffin{l}{H}
{3.33pt}{0pt}
\coffin_typeset:Nnnnn
\l_tmpb_coffin{l}{T}
{0pt}{0pt}
\group_end:
}
\ExplSyntaxOff
\myalign{before}{%
\hbox{the main text}
\hbox{that has several lines}
\hbox{of unknown width}}%
{after}
\bye
答案2
\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\newcommand\threebox[3]{%
\renewcommand\stacktype{L}%
\strutlongstacks{T}%
\savestack\middlebox{\Longstack[l]{#2}}%
\raisebox{\dimexpr\ht\middleboxcontent-\ht\strutbox}{#1} \middlebox{} #3%
}
\begin{document}
\threebox{before}{the main\\text\\that has\\several lines\\of unknown\\ width }{after}
\quad\threebox{before}{with a g\\descender}{after g}\bigskip
\threebox{g before}{with a\\g descender}{after}
\end{document}