
Dados vários parágrafos em ConTeXt ou TeX simples, como posso garantir que todos os parágrafos usem a mesma quantidade de espaço vertical, adicionando espaço em branco ao final, como o parágrafo mais longo do conjunto? Por exemplo:
This is a paragraph
with only two lines.
This paragraph is a
little bit longer and it
has three lines.
This is the longest
paragraph, as it has
a second, third, and
fourth line.
Os parágrafos acima receberiam espaço em branco posteriormente, de modo que todos ocupassem a mesma quantidade de espaço vertical que o último parágrafo, porque é mais longo, por exemplo:
This is a paragraph
with only two lines.
This paragraph is a
little bit longer and it
has three lines.
This is the longest
paragraph, as it has
a second, third, and
fourth line.
Responder1
Outra solução baseada em ConTeXt, mas esta funciona em uma única passagem. Requer que você armazene o conteúdo em buffers, depois meça todos os buffers e defina a altura para a altura máxima (não necessariamente a altura do último parágrafo).
\newdimen\maxbufferheight
\def\placebuffertomaximumheight[#1]%
{\maxbufferheight\zeropoint
\processcommalist[#1]\domeasurebuffermaxheight
\processcommalist[#1]\doplacebuffertomaxheight}
\def\domeasurebuffermaxheight#1%
{\setbox\scratchbox\vbox{\getbuffer[#1]}%
\scratchdimen\ht\scratchbox
\ifdim\scratchdimen>\maxbufferheight
\maxbufferheight=\scratchdimen
\fi}
\def\doplacebuffertomaxheight#1%
{\ruledvbox to \maxbufferheight
{\getbuffer[#1]}%
\blank[none]} %change \blank[..] to \par to get regular inter-para space
\starttext
\startbuffer[one]
Single line
\stopbuffer
\startbuffer[two]
\input tufte
\stopbuffer
\startbuffer[three]
\input ward
\stopbuffer
\placebuffertomaximumheight[one,two,three]
\stoptext
Depois de ter o mecanismo básico, é simples envolvê-lo em uma macro.
\newcount\nofmeasuredparagraphs
\def\startparagraph
{\increment\nofmeasuredparagraphs
\grabbufferdata[measuredparagraph-\nofmeasuredparagraphs][startparagraph][stopparagraph]}
\def\stopparagraph{}
\def\startmeasuredparagraph
{\nofmeasuredparagraphs\zeropoint}
\def\stopmeasuredparagraph
{\maxbufferheight\zeropoint
\dorecurse\nofmeasuredparagraphs
{\domeasurebuffermaxheight{measuredparagraph-\recurselevel}}%
\dorecurse\nofmeasuredparagraphs
{\doplacebuffertomaxheight{measuredparagraph-\recurselevel}}}
\starttext
\startmeasuredparagraph
\startparagraph
Single line
\stopparagraph
\startparagraph
\input tufte
\stopparagraph
\startparagraph
\input ward
\stopparagraph
\stopmeasuredparagraph
\stoptext
Isto dá
Estou usando \ruledvbox
para que você possa ver a caixa. Mude para \vbox
se não quiser ver a caixa.
Responder2
você pode usar
\vbox to 5cm{stuff.......\vfill}
Para forçar uma caixa do tamanho vertical correto, preencha com espaço no final.
em vez de 5 cm você pode medir uma das caixas primeiro para
\setbox0\vbox{longest stuff....}
então para cada parágrafo você pode fazer
\vbox to \ht0{stuff.......\vfill}
Responder3
Aqui eu forneço uma solução mais ConTeXtish baseada na mesma ideia da solução de David. Ele incorpora o agoradados de duas passagensmecanismo.
\defineframedtext [normalparagraph]
[
frame=off,
offset=overlay,
width=\textwidth,
height=\datasetvariable{lastparagraph}{last}{height},
]
\definedataset [lastparagraph]
\newbox\mylastbox
\definestartstop [lastparagraph]
[
before=\setups{last:before},
after=\setups{last:after},
]
\startsetups last:before
\setbox\mylastbox\vbox\bgroup
\stopsetups
\startsetups last:after
\egroup
\setdataset [lastparagraph] [last] [height=\the\ht\mylastbox]
\box\mylastbox
\stopsetups
\starttext
\startnormalparagraph
\framed[align=normal]{\input knuth\par}
\stopnormalparagraph
\startnormalparagraph
\framed[align=normal]{\input ward\par}
\stopnormalparagraph
\startlastparagraph
\input knuth
\stoplastparagraph
\stoptext
Resultado:
Os normalparagraph
s são vbox
es simples com a altura do último parágrafo. O height
valor é obtido do conjunto de dados de duas passagens. lastparagraph
Também é um arquivo cuja vbox
altura é medida e salva no .tuc
arquivo. Os \framed
seguintes \starttext
são adicionados apenas para ilustração. Preencha-o com seu conteúdo.