I want some text to take up the same amount of space as other text. For example, in the script below, how do I make BOB take up the same amount of space as MELISSA so the beginning of their dialogue lines are aligned?

\documentclass{article}
\begin{document}
BOB Hello, Melissa.
MELISSA Hello, Bob.
\end{document}
up vote 6 down vote accepted

Something of the style:

\documentclass{article}
\newlength{\blob}
\settowidth{\blob}{MELISSA}
\begin{document}
\makebox[\blob][l]{BOB} Hello, Melissa.

\makebox[\blob][l]{MELISSA} Hello, Bob.
\end{document}

will work if the dialogs are less than one line. If the dialogs could be longer, you could try to use hanging paragraphs:

\documentclass{article}
\usepackage{hanging}
\newlength{\blob}
\settowidth{\blob}{MELISSA } %% longest with space
\newcommand{\start}[1]{%
  \parindent0pt
  \everypar={\hangpara{\blob}{0}}
  \makebox[0pt][r]{\makebox[\blob][l]{#1}}%
  \ignorespaces
}
\newcommand{\dstop}{%
  \parindent0pt
  \everypar={}
}
\begin{document}
\start{BOB} Hello, Melissa. 

\start{MELISSA} Hello, Bob. Speaking  Speaking  Speaking  Speaking
Speaking  Speaking  Speaking  Speaking  Speaking  Speaking  Speaking
Speaking

And more speaking speaking speaking...

\dstop

Normal paragraph here 

\end{document}

Which gives:

Example

You can easily modify \start and \dstop macros to change fonts, add skips etc. that can make the dialogs easier to read.

  • 1
    I'm using the command \leftskip=16pt \parindent=-16pt at the beginning of my document to create that "hanging" indent, without needing to repeat anything (like your command \start), as recommended by this answer tex.stackexchange.com/a/140244/9757 Is there a way to "get" the length of MELISSA, so I could do something like \leftskip=\length{MELISSA}? – jamaicanworm Nov 27 '13 at 2:36
  • @jamaicanworm Either Rmano or me are suggesting you the macro \settowidth (probably with some corrections of a space). – Przemysław Scherwentke Nov 27 '13 at 2:43
  • Figured it out: I can do \leftskip=\blob \parindent=-blob – jamaicanworm Nov 27 '13 at 5:06

It seems that you need this for a drama-like typesetting. Then probably one of specialized packages will be useful, for example dramatist, drama or play.

But if you only need to put BOB in the box of dimension of MELISSA, you can do:

\newlength{\melis}
\settowidth{\melis}{MELISSA}
\makebox[\melis][l]{BOB}
  • 1
    If one loads the package xspace and defines the macro \newcommand\BOB{\makebox[\melis][l]{BOB}}\xspace, one could write \BOB whenever it's necessary to typeset the word BOB to width of the word MELISSA. The xspace macro makes it unnecessary to remember to insert ` after \BOB` to get a word space. – Mico Nov 27 '13 at 8:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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