1

I am a beginner in Latex. This is my problem.

I would like to type set a dialogue between three characters. I found the dialogue environment but it does not exactly cope with what I expect. The following solution almost do what I want :

    % arara: pdflatex

\documentclass{article}
\usepackage{blindtext}
\usepackage{enumitem}
\usepackage{xparse}
\DeclareDocumentCommand \dia { o m } {%
    \begin{itemize}[%
        ,label=\IfNoValueTF {#1} {}{#1:}
        ,nosep % optional
        ,font=\color{red}
        ]
        \item #2
    \end{itemize}%  
    }

\begin{document}
\dia[First guy]{Hi, how are you?}
\dia[Second guy]{Fine and you?}
\dia[Guy with long hair]{My god, this dialogue is so boring.}
\dia[first guy]{Indeed, but have you heard that \blindtext}
\end{document}

[Result[1] But I would like to do some adjustments and therefore need to understand how it works.

  1. I would like to enlarge the space between the character's name (label) and the speech.
  2. what are the o and m in the \declareDocumentCommand
  3. how the \IfNoValueTF works ?

Thanks for your help.

2 Answers 2

2

For the first point, just put some labelsep in your description of your label inside the itemize environment. For the other two questions, just read the xparse document: http://www.chiark.greenend.org.uk/doc/texlive-doc/latex/l3packages/xparse/xparse.pdf.

  1. The o stands for optional argument and the m for mandatory argument. You don't need to put the name of who is talking but you must put a dialogue as an argument. Try yourself to erase First guy in your first dialogue or to quit the square brackets and do the same with the curly braces and see the output and the error given, respectively.
  2. The \IfNoValueTF just checks if the optional argument was given or not and it will write what you put if some argument is given, if not, it writes some horizontal spacing.

Also, I loaded the xcolor package to avoid compiling errors. Change black to red, for example, and it will change your characters colours.

\documentclass{article}
\usepackage{blindtext}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{xparse}
\DeclareDocumentCommand\dia{ o m }{%
    \begin{itemize}[%
        ,label=\IfNoValueTF {#1} {}{#1:}
        ,labelsep=8mm
        ,nosep % optional
        ,font=\color{black}
        ]
        \item #2
    \end{itemize}%  
    }

\begin{document}
\dia[First guy]{Hi, how are you?}
\dia[Second guy]{Fine and you?}
\dia[Guy with long hair]{My god, this dialogue is so boring.\\ %start a new line
Yeah! It's so boring.}
\dia[First guy]{Indeed, but have you heard that \blindtext}
\end{document}

Example

Hope it works as you want!

4
  • Thanks a lot for your two answers. Do you know how can I add a paragraph inside an item ?
    – JBOP
    Mar 11, 2020 at 20:33
  • I don't know exactly what you want, but I updated my answer. Just put \\ where you want to put a new paragraph @JBOP. Mar 12, 2020 at 11:14
  • @SebastiánV.Romero thanks a lot. I mean can you seperate the speaker and their words to two lines? Mar 29, 2020 at 13:07
  • I don't if I understand you correctly but substitute in the line 13 \item #2 for \item \phantom{}\\\phantom{}\\#2. Hope it works as you want! :D @PaulChen Mar 29, 2020 at 20:26
1

I'll try to help!

  1. To enlarge the space between the characters name and what they are saying, you should add ,labelsep=12.5mm in the itemize-section. You can change the length to what you desire.
  2. o means optional, m stands for mandatory. This means, that the first argument of the environment ([label]) is optional, the second, i.e. the input in \dia{Hi! I'm the input!} is not.
  3. The \IfNoValueTF "executes" what you wrote behind it, if no [label] was found, e.g. when you use \dia{Lemme say something} and not \dia[steve]{Lemme say something!}. In this case, it will create a line.

If you have further questions, don't be afraid to ask!

1
  • can you seperate the speaker and their words to two lines? Mar 29, 2020 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.