8

I want to make a dialogue between two people with the "commenting icon" in front of every sentence. I somewhat got what I want by using enumitem and fontawesome packages. enter image description here

Here is my code so far.

\documentclass{article}
\usepackage{enumitem}
\usepackage{fontawesome}
\usepackage{xcolor}
\begin{document}
    \begin{itemize}
        \item[\color{blue!70!white}\faCommenting] First person
        \item[\color{green!70!black}\faCommentingO] Second person
        \item[\color{blue!70!white}\faCommenting] First person
    \end{itemize}
\end{document}

Now I'd like to define it as a new environment to use this multiple times. I know there is a \labelitemi command but it makes change for all items, for this I am not sure how to do it.

I did look up for old questions and found this but couldn't understand the steps to have them fit my case.

2 Answers2

8

You can make a command that changes its own definition, and use that as the label, for example like this:

\documentclass{article}

\usepackage{enumitem} \usepackage{fontawesome} \usepackage{xcolor}

\makeatletter \def\speech@bubble@a{% \color{blue!70!white}\faCommenting \global\let\speech@bubble\speech@bubble@b } \def\speech@bubble@b{% \color{green!70!black}\faCommentingO \global\let\speech@bubble\speech@bubble@a } \newlist{dialog}{itemize}{1} \newlist{dialog}{itemize}{1} \setlist[dialog]{ before={\global\let\speech@bubble\speech@bubble@a}, label={\speech@bubble}, } \setlist[dialog]{ before={\global\let\speech@bubble\speech@bubble@b}, label={\speech@bubble}, } \makeatother

\begin{document}

First person first: \begin{dialog} \item bla \item bla \item bla \item bla \item bla \end{dialog}

Second person first: \begin{dialog} \item bla \item bla \item bla \item bla \item bla \end{dialog}

\end{document}

MWE output

schtandard
  • 14,892
7

Here is a solution with the \newtoggle command from etoolbox. To simplify the use of this solution, I defined a new itemize-like environment, alternitem:

\documentclass{article}
\usepackage{enumitem}
\usepackage{fontawesome}
\usepackage{xcolor}
\usepackage{etoolbox}
%
\newtoggle{greeny}
\newlist{alternitem}{itemize}{1}
\setlist[alternitem]{label={\iftoggle{greeny}%
{\color{green!70!black}\faCommentingO\global\togglefalse{greeny}}%
{\color{blue!70!white}\faCommenting\global\toggletrue{greeny}}%
}}

\begin{document}

\begin{alternitem} \item First person \item Second person \item First person \item First person \item Second person \item First person \end{alternitem}

\end{document}

enter image description here

Bernard
  • 271,350