TeX - LaTeX Asked by Lukest_Dang on March 7, 2021
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.
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.
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}faCommentingOglobaltogglefalse{greeny}}%
{color{blue!70!white}faCommentingglobaltoggletrue{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}
Correct answer by Bernard on March 7, 2021
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
defspeech@bubble@a{%
color{blue!70!white}faCommenting
globalletspeech@bubblespeech@bubble@b
}
defspeech@bubble@b{%
color{green!70!black}faCommentingO
globalletspeech@bubblespeech@bubble@a
}
newlist{dialog}{itemize}{1}
newlist{dialog*}{itemize}{1}
setlist[dialog]{
before={globalletspeech@bubblespeech@bubble@a},
label={speech@bubble},
}
setlist[dialog*]{
before={globalletspeech@bubblespeech@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}
Answered by schtandard on March 7, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP