First up, im relatively new to latex and completely new to tikz. What I'm trying to do is create a chat interface in latex with tikz. My desired result would be something like that:
\begin{chat}
Question
Answer
Question
Answer
\end{chat}
Regarding other threads here, the only thing I've found was this messenger interface document class, but I want to embedd it into my existing document and also this a little more than want (android gui, message input field, ...).
What I've done so far is create those nodes manually and adjust the coordinates manually (especially for multiline messages). The result of this code is the image above.
\begin{tikzpicture}
\definecolor{chatcolor1}{HTML}{5fedb7}
\definecolor{chatcolor2}{HTML}{b6b8b7}
\fontfamily{cmss}\selectfont
\node[align=left, text width=5cm, fill=chatcolor2, rounded corners=1mm, anchor=north west] at (0,0) {Question};
\node[align=right, text width=5cm,fill=chatcolor1, rounded corners=1mm, anchor=north west] at (2,-0.7) {Answer};
\node[align=left, text width=5cm, fill=chatcolor2, rounded corners=1mm, anchor=north west] at (0,-1.4) {Question};
\node[align=right, text width=5cm,fill=chatcolor1, rounded corners=1mm, anchor=north west] at (2,-2.1) {Answer};
\end{tikzpicture}
Now the idea was to make the code reusable, so that I don't have to copy paste that and adjust the coordinates manually every time. To do so I tried creating an environment with the environ package. This should iterate over the lines in the \BODY and create a node for each line.
\NewEnviron{chat}{%
\definecolor{chatcolor1}{HTML}{5fedb7}
\definecolor{chatcolor2}{HTML}{b6b8b7}
\fontfamily{cmss}\selectfont
\begin{tikzpicture}
\foreach \line in \BODY
{\node[align=left, text width=5cm, fill=chatcolor2, rounded corners=1mm, anchor=north west] at (0,0) {\line};}
\end{tikzpicture}
}
However this does create a node, but all the content is seen as a single line. If I add linebreaks between each line in the \begin{chat} ... \end{chat} it throws the following error: Paragraph ended before \pgffor@normal@list was complete. \end{chat}
Does this approach sound reasonable for you? If yes how do I get it to work?
If not, I am thankful for any other approaches to the problem.
Thanks in advance.

