2 つ以上の段落で同じ量の垂直スペースを使用するように設定するにはどうすればよいですか?

2 つ以上の段落で同じ量の垂直スペースを使用するように設定するにはどうすればよいですか?

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 ベースのソリューションですが、これは 1 回のパスで動作します。コンテンツをバッファーに保存し、すべてのバッファーを測定して高さを最大の高さ (必ずしも最後の段落の高さではありません) に設定する必要があります。

\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の代わりに、まず箱の1つを測って

 \setbox0\vbox{longest stuff....}

そして各段落ごとに

\vbox to \ht0{stuff.......\vfill}

答え3

ここでは、デイビッドの解決策と同じアイデアに基づいた、より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

結果:

結果

は、最後の段落の高さを示すnormalparagraph単純な です。値は、2 パス データ セットから取得されます。も であり、その高さが測定されてファイルに保存されます。以降の部分は、説明のために追加しただけです。コンテンツを入力してください。vboxheightlastparagraphvbox.tuc\framed\starttext

関連情報