
ConTeXt 또는 일반 TeX의 여러 단락이 있는 경우 세트에서 가장 긴 단락처럼 끝에 공백을 추가하여 모든 단락이 동일한 양의 수직 공간을 사용하도록 어떻게 보장할 수 있습니까? 예:
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.
위의 단락은 나중에 공백이 추가되어 모두 마지막 단락과 동일한 양의 수직 공간을 차지합니다. 예를 들어 다음과 같습니다.
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.
답변1
또 다른 ConTeXt 기반 솔루션이지만 이 솔루션은 단일 패스로 작동합니다. 콘텐츠를 버퍼에 저장한 다음 모든 버퍼를 측정하고 높이를 최대 높이(마지막 단락의 높이일 필요는 없음)로 설정해야 합니다.
\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
기본 메커니즘이 있으면 이를 매크로로 래핑하는 것이 간단합니다.
\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
이것은
\ruledvbox
박스가 보이도록 사용하고 있습니다 . \vbox
상자를 보고 싶지 않으면 로 변경하세요 .
답변2
당신이 사용할 수있는
\vbox to 5cm{stuff.......\vfill}
올바른 수직 크기의 상자를 강제로 만들기 위해 끝에 공백을 채웠습니다.
5cm 대신 상자 중 하나를 먼저 측정할 수 있으므로
\setbox0\vbox{longest stuff....}
그런 다음 각 단락마다 할 수 있습니다
\vbox to \ht0{stuff.......\vfill}
답변3
여기에서는 Davids 솔루션과 동일한 아이디어를 기반으로 더 많은 ConTeXtish 솔루션을 제공합니다. 지금을 담고 있다2단계 데이터기구.
\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
결과:
s 는 마지막 단락의 높이를 갖는 normalparagraph
단순한 es입니다 . vbox
값 height
은 2단계 데이터 세트에서 선택됩니다. 또한 높이가 측정되어 파일에 저장되는 lastparagraph
입니다 . 이후 는 설명을 위해 추가되었습니다. 귀하의 콘텐츠로 채워보세요.vbox
.tuc
\framed
\starttext