如何将两段逐字文本并排放置?使用\starttyping
within\startcombination
将行连在一起,而不是在行之间断开。
梅威瑟:
\starttext
\startcombination[2*1]
{
\starttyping
This is sample line 1
This is sample line 2
This is sample line 3
\stoptyping
} { A }
{
\starttyping
Alternative line 1
Alternative line 2
Alternative line 3
\stoptyping
} { B }
\stopcombination
\stoptext
我已\placesidebyside
尽力尝试,结果类似。
答案1
组合的主要用途是将多幅图像排列在一个块中,因此 ConTeXt 使用水平框来存储图像。当您想要将多行文本放在组合中时,您必须将其放在允许换行的垂直框中。
虽然您可以使用常规\framed
(或其\startframed
替代)命令,但该framedtext
环境更适合,因为它在封闭文本的顶部和底部具有更好的间距。
要获得框的适当宽度,您必须添加location=none
,framedtext
否则它将占据整个文本块的宽度。对于strip=yes
环境,typing
请确保从输出中删除行开头的前导空格。
\starttext
\startcombination[2*1]
\startcontent
\startframedtext[location=none,frame=off,offset=0pt,width=fit] % width=.45\textwidth
\starttyping[strip=yes]
This is sample line 1
This is sample line 2
This is sample line 3
\stoptyping
\stopframedtext
\stopcontent
\startcaption
A
\stopcaption
\startcontent
\startframedtext[location=none,frame=off,offset=0pt,width=fit] % width=.45\textwidth
\starttyping[strip=yes]
Alternative line 1
Alternative line 2
Alternative line 3
\stoptyping
\stopframedtext
\stopcontent
\startcaption
B
\stopcaption
\stopcombination
\stoptext
当文档中拥有多个组合块时,您可以创建额外的实例typing
并framedtext
仅对它们设置一次。
\defineframedtext
[CombinationFrame]
[location=none,
frame=off,
offset=0pt,
width=fit] % width=.45\textwidth
\definetyping
[CombinationCode]
[strip=yes,
before=\startCombinationFrame,
after=\stopCombinationFrame]
\starttext
\startcombination[2*1]
\startcontent
\startCombinationCode
This is sample line 1
This is sample line 2
This is sample line 3
\stopCombinationCode
\stopcontent
\startcaption
A
\stopcaption
\startcontent
\startCombinationCode
Alternative line 1
Alternative line 2
Alternative line 3
\stopCombinationCode
\stopcontent
\startcaption
B
\stopcaption
\stopcombination
\stoptext
当您有更长的代码块时,将源代码放在缓冲区中然后在组合中加载缓冲区会很有用。
\defineframedtext
[CombinationFrame]
[location=none,
frame=off,
offset=0pt,
width=fit] % width=.45\textwidth
\definetyping
[CombinationCode]
[strip=yes,
before=\startCombinationFrame,
after=\stopCombinationFrame]
\starttext
\startbuffer[sample-line]
This is sample line 1
This is sample line 2
This is sample line 3
\stopbuffer
\startbuffer[alternative-line]
Alternative line 1
Alternative line 2
Alternative line 3
\stopbuffer
\startcombination[2*1]
\startcontent
\typeCombinationCodebuffer[sample-line]
\stopcontent
\startcaption
A
\stopcaption
\startcontent
\typeCombinationCodebuffer[alternative-line]
\stopcontent
\startcaption
B
\stopcaption
\stopcombination
\stoptext
答案2
您可以使用段落。也可以使用打字。
\defineparagraphs [Block] [n=2]
\starttext
\startBlock
\starttyping
This is sample line 1
This is sample line 2
This is sample line 3
\stoptyping
\Block
\starttyping
Alternative line 1
Alternative line 2
Alternative line 3
\stoptyping
\stopBlock
\stoptext
答案3
组合以水平模式排版,因此不会有换行符。您可以使用\framed
它来制作启用换行符的框。我建议将其与缓冲区结合使用。
\starttext
\startbuffer[A]
This is sample line 1
This is sample line 2
This is sample line 3
\stopbuffer
\startcombination[2*1]
{%
\startframed[frame=off,width=fit,align=right,strut=no]
\typebuffer[A][before=,after=]
\stopframed
}{A}
{%
\startframed[frame=off,width=fit,align=right,strut=no]
\setuptyping[before=,after=]
\starttyping
Alternative line 1
Alternative line 2
Alternative line 3
\stoptyping
\stopframed
}{B}
\stopcombination
\stoptext