将单行居中于其他命令之间,不要将多行居中

将单行居中于其他命令之间,不要将多行居中

我正在为我们的戏剧俱乐部编写一个 latex 类,用于协作编写戏剧剧本。因此,只要使用起来尽可能简单,该类可以根据需要尽可能复杂。

我们在类中有一个“说”命令,它会在左侧输出演员的名字和演员所说的文字。

然后我们有较长的文本块,通常是场景的介绍和设置。但是,有时我们有单行,不是通常的文本,而是导演命令。这些应该居中。

我想以某种方式设置类,使得两个\says命令之间的没有任何格式/命令的单个段落始终居中。但是,当有多个段落时,它应该是两端对齐的。

使用乳胶可以实现这一点吗?如果可以,我该怎么做?


添加示例源:

% ...
The stage is empty. On the front of the stage, there is a typewriter on a
table. The table is lit. In the typewriter there is a page with LaTeX code 
on it. it is a stage play. pages upon pages of latex code are clutterd
around that table. commented by hand with percent-signs.

At the back of the stage, there is a black curtain. The floor of the stage 
is a black carpet. The rest of the stage is dark and empty.

\says{Editor}{It is called La Tech, not latex like you fetishists think}

% this line would be centered, as it is only one paragraph between two "says"
he sinks to the ground

\says{Random Guy}{Why don't you write it like that if it is called like that?}

%these lines won't be centered as there are two paragraphs.
The light is getting brighter. The stage is still empty.

Now lightly latex-dressed women enter the stage

\says{Editor}{What the heck is that?}

或许可以定义一个控制字符来定义导演输入,比如> he sinks to the ground

答案1

您可以尝试使用如下新命令:

\documentclass[12pt]{article}

\newcommand{\dirsays}[1]{\sbox{0}{#1}%
  \ifdim\wd0>\linewidth
    #1
  \else
    \noindent\makebox[\linewidth]{#1}%
  \fi}

\begin{document}

\dirsays{I am writing a latex-class for our theatre club.}

\bigskip
\dirsays{I am writing a latex-class for our theatre club for collaborative writing of theatre-scripts. So the class can be as complex as needed, as long as the usage is as easy as possible.}

\end{document}

在此处输入图片描述

相关内容