2

I have built a source file for writing theatre scripts. I wanted to know if it is possible to align the characters' names inside, as shown in the picture.

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec}

% fonts
\usepackage{nimbusmononarrow}
\renewcommand*\familydefault{\ttdefault}

% def characters
\newcommand\MAN{\par\vspace{5mm}\noindent\makebox[35mm][l]{MAN}\hangindent=35mm }
\newcommand\WOMAN{\par\vspace{5mm}\noindent\makebox[35mm][l]{WOMAN}\hangindent=35mm }

\begin{document}

\MAN
This is my first joke!

\WOMAN
This is my first joke!

\end{document}

enter image description here

0

3 Answers 3

6

You could use something like this. In case you can't use some character name as a command, use the optional argument of \newcharacter to specify the command name.

Example: \newcharacter[ManCmd]{MAN} defines command \ManCmd which will print “MAN” as character name in the script.

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}             % for the dummy text

% Fonts
\usepackage{nimbusmononarrow}
\renewcommand*\familydefault{\ttdefault}

\newlength{\textOffset}
\setlength{\textOffset}{35mm}

\newlength{\maxCharnameLen}
\setlength{\maxCharnameLen}{15mm}

\ExplSyntaxOn
\NewDocumentCommand \newcharacter { O{#2} m }
  {
    \cs_new_protected:cpn {#1}
      {
        \par \vspace { 5mm } \noindent
        \makebox [\textOffset] [l] { \makebox [\maxCharnameLen] [r] {#2} }
        \dim_set_eq:NN \hangindent \textOffset
      }
  }
\ExplSyntaxOff

\newcharacter{MAN}
\newcharacter{WOMAN}

\begin{document}

\MAN
This is my first joke!

\WOMAN
This is my first joke! \lipsum*[1][1-3]

\end{document}

enter image description here

3

You can define an abstraction.

Here's a version that also measures the names, so it can set the space to the strictly necessary width. Optionally, you can decide that a name should stick in the margin.

\documentclass[a4paper,12pt]{article}

% fonts
\usepackage{nimbusmononarrow}
\renewcommand*\familydefault{\ttdefault}

% def characters
\newlength{\characterswidth}
\newlength{\characterssep}

\NewDocumentCommand{\definecharacter}{smm}{%
  % #1 = possible * (no adjustment to the global width)
  % #2 = command
  % #3 = name
  \NewDocumentCommand{#2}{}{%
    \par\addvspace{5mm}
    \hangindent=\dimexpr\characterswidth+\characterssep\relax
    \noindent
    \makebox[\characterswidth][r]{#3}\hspace{\characterssep}%
  }%
  \IfBooleanT{#1}{%
    \AtBeginDocument{%
      % measure the name
      \settowidth{\dimen0}{#3}%
      \ifdim\characterswidth<\dimen0
        \setlength{\characterswidth}{\dimen0}%
      \fi
    }%
  }%
}
\AtBeginDocument{\setlength{\characterssep}{2em}}

\definecharacter{\MAN}{MAN}
\definecharacter{\WOMAN}{WOMAN}
\definecharacter{\TOOLONG}{STICKSINMARGIN}

\begin{document}
\raggedright

\MAN
This is my first joke!

\WOMAN
This is my first joke!

\MAN
This is my first joke! This is my first joke! This is my first joke!
This is my first joke! This is my first joke! This is my first joke!
This is my first joke! This is my first joke! This is my first joke!
This is my first joke! This is my first joke! This is my first joke!


\TOOLONG
Not a joke at all.

\end{document}

enter image description here

It is necessary to do the measuring at begin document, when \normalfont has already been issued, so the chosen font will be used for measuring.

3
  • Hi @egreg. What is \dimen0 in your code for? Is it an internal register we can use "on deman" to avoid creating names? Are there any other similar constructs let's say for skips, lengths etc.? Thanks
    – Celdor
    Commented Jun 9, 2022 at 9:54
  • 1
    @Celdor It's a “scratch length” for temporary usage. You can use \dimen with a digit from 0 to 9 and the same for the other registers (except \count, but including \box). The usual convention is that even digits are used for local settings and odd ones for global settings.
    – egreg
    Commented Jun 9, 2022 at 9:58
  • Thanks. It makes more sense now. I tried to find more about it but I guess it is not very common topic.
    – Celdor
    Commented Jun 9, 2022 at 11:13
1

Try this:

\documentclass{article}
\usepackage{enumitem, lipsum}

\begin{document}
\begin{description}[align=right,labelwidth=.66cm]
  \item[First]  The first item
  \item[Second]  The second item
  \item[Terzo incomodo pure]  \lipsum[1]
\end{description}
\end{document}

Output:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .