![2 个成员对话,每个输入都在左右框中,标题为额外信息](https://linux22.com/image/424591/2%20%E4%B8%AA%E6%88%90%E5%91%98%E5%AF%B9%E8%AF%9D%EF%BC%8C%E6%AF%8F%E4%B8%AA%E8%BE%93%E5%85%A5%E9%83%BD%E5%9C%A8%E5%B7%A6%E5%8F%B3%E6%A1%86%E4%B8%AD%EF%BC%8C%E6%A0%87%E9%A2%98%E4%B8%BA%E9%A2%9D%E5%A4%96%E4%BF%A1%E6%81%AF.png)
使用 Expl3、environ 和 tcolorbox,可以创建一个环境,将以白线结尾的每段文本放在一个框中。我想修改下面给出的代码,以便它还填充 tcolobox 框的“Title”可选字段和上下部分。例如,以循环方式按相同顺序填充“Tile”、“上部”部分和“下部”部分,因为它找到以空白行或 \end{mynewenviron} 结尾的行。“mynewenviron”是为此目的创建的环境的名称。
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{xcolor}
\usepackage{varwidth}
\usepackage{environ}
\usepackage{xparse}
\newlength{\bubblesep}
\newlength{\bubblewidth}
\setlength{\bubblesep}{2pt}
\AtBeginDocument{\setlength{\bubblewidth}{.75\textwidth}}
\newcommand{\bubble}[1]{%
\tcbox[
on line,
arc=2.5mm,
rounded corners,
]{\begin{varwidth}{\bubblewidth}#1\end{varwidth}}%
}
\ExplSyntaxOn
\seq_new:N \l__ooker_bubbles_seq
\tl_new:N \l__ooker_bubbles_first_tl
\tl_new:N \l__ooker_bubbles_last_tl
\NewEnviron{rightbubbles}
{
\begin{flushright}
\sffamily
\seq_set_split:NnV \l__ooker_bubbles_seq { \par } \BODY
\int_compare:nTF { \seq_count:N \l__ooker_bubbles_seq < 2 }
{
\bubble{\BODY}\par
}
{
\seq_pop_left:NN \l__ooker_bubbles_seq \l__ooker_bubbles_first_tl
\seq_pop_right:NN \l__ooker_bubbles_seq \l__ooker_bubbles_last_tl
\bubble{\l__ooker_bubbles_first_tl}
\par\nointerlineskip
\addvspace{\bubblesep}
\seq_map_inline:Nn \l__ooker_bubbles_seq
{
\bubble{##1}
\par\nointerlineskip
\addvspace{\bubblesep}
}
\bubble{\l__ooker_bubbles_last_tl}
\par
}
\end{flushright}
}
\ExplSyntaxOff
\begin{document}
\begin{rightbubbles}
Right-aligned gray bubbles (103, 184,104) with white text
Bubbles only break after a paragraph (equivalent to an enter press
when chatting). Long message with multiple lines will be kept in one bubble.
Left and right edges are round.
Single
\end{rightbubbles}
\begin{rightbubbles}
Single
\end{rightbubbles}
\end{document}