3

I'm trying to make a document with chat history and found a sample code here except for the twocolumn option in the documentclass.

But the chat bubbles don't keep inside the column. Someone who know how to correct it?

I want the chat history in two column pages.

\documentclass[11pt,a4paper, twocolumn]{article} \usepackage[many]{tcolorbox} \usepackage{xcolor} \usepackage{varwidth} \usepackage{environ} \usepackage{xparse} \newlength{\bubblesep} \newlength{\bubblewidth} \setlength{\bubblesep}{2pt} \AtBeginDocument{\setlength{\bubblewidth}{.75\textwidth}} \definecolor{bubblegreen}{RGB}{103,184,104} \definecolor{bubblegray}{RGB}{241,240,240} \newcommand{\bubble}[4]{% \tcbox[ on line, arc=4.5mm, colback=#1, colframe=#1, #2, ]{\color{#3}#4}% } \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{bubblegreen}{rounded~corners}{white}{\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{bubblegreen}{sharp~corners=southeast}{white}{\l__ooker_bubbles_first_tl} \par\nointerlineskip \addvspace{\bubblesep} \seq_map_inline:Nn \l__ooker_bubbles_seq { \bubble{bubblegreen}{sharp~corners=east}{white}{##1} \par\nointerlineskip \addvspace{\bubblesep} } \bubble{bubblegreen}{sharp~corners=northeast}{white}{\l__ooker_bubbles_last_tl} \par } \end{flushright} } \NewEnviron{leftbubbles} { \begin{flushleft} \sffamily \seq_set_split:NnV \l__ooker_bubbles_seq { \par } \BODY \int_compare:nTF { \seq_count:N \l__ooker_bubbles_seq < 2 } { \bubble{bubblegray}{rounded~corners}{black}{\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{bubblegray}{sharp~corners=southwest}{black}{\l__ooker_bubbles_first_tl} \par\nointerlineskip \addvspace{\bubblesep} \seq_map_inline:Nn \l__ooker_bubbles_seq { \bubble{bubblegray}{sharp~corners=west}{black}{##1} \par\nointerlineskip \addvspace{\bubblesep} } \bubble{bubblegray}{sharp~corners=northwest}{black}{\l__ooker_bubbles_last_tl}\par } \end{flushleft} } \ExplSyntaxOff \title{Title of my document} \date{2013-09-01} \author{John Doe} \begin{document} \maketitle \pagenumbering{gobble} \newpage \pagenumbering{arabic} \begin{leftbubbles} Left-aligned gray bubbles (241, 240, 240) with black text Right-aligned green 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. \end{leftbubbles} \begin{rightbubbles} Single \end{rightbubbles} \begin{leftbubbles} Left-aligned gray bubbles (241, 240, 240) with black text Right-aligned green 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. \end{leftbubbles} \begin{rightbubbles} Single \end{rightbubbles} \begin{leftbubbles} Left-aligned gray bubbles (241, 240, 240) with black text Right-aligned green 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. \end{leftbubbles} \begin{rightbubbles} Single \end{rightbubbles} \begin{leftbubbles} Left-aligned gray bubbles (241, 240, 240) with black text Right-aligned green 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. \end{leftbubbles} \begin{rightbubbles} Single \end{rightbubbles} \begin{leftbubbles} Left-aligned gray bubbles (241, 240, 240) with black text Right-aligned green 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. \end{leftbubbles} \begin{rightbubbles} Single \end{rightbubbles} \end{document} 

enter image description here

0

1 Answer 1

3

You need to change the settings in the \bubble command. tcolorbox offers an option tcbox width=auto limited which sets the width of the \tcbox (the underlying command of \bubble) to automatic, i.e. it obeys the width of the contents, but limited to a maximum. To set that maximum you can use width=\columnwidth option. Thus, changing the definition of bubble is enough:

\newcommand{\bubble}[4]{% \tcbox[ on line, arc=4.5mm, colback=#1, colframe=#1, tcbox width=auto limited, % <-- added width=\columnwidth, % <-- added #2, ]{\color{#3}#4}% } 

output:

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.