在我的文档中,我将 设置\parindent
为0pt
并将\parskip
设置为\baselineskip
。但是,这种格式不适合对话框,因此我定义了一个环境来改变间距。
\newenvironment{Dialog}{%
\par
\setlength{\parskip}{0pt}
\setlength{\parindent}{1em}}{%
\par
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}
}
问题是,对话结束后我仍然得到垂直空间,这是我不想要的。
我怎样才能摆脱它?
完整 MWE
\documentclass{article}
\newenvironment{Dialog}{%
\par
\setlength{\parskip}{0pt}
\setlength{\parindent}{1em}}{%
\par
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}
}
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}
\begin{document}
Some text here, now the dialog starts
\begin{Dialog}
--- Which phrase should I not google under any circumstances?
--- ``Crazy LaTeX stuff''.
\end{Dialog}
Now the text continues.
\end{document}
答案1
下面使用\vskip\dialogunskip
(with \dialogunskip=-\parskip
) 来消除空格。它还显示了非常长的对话行的问题:如果文本行长于一行且结束于下一行的边缘,会发生什么情况?那么您就无法分辨语音在哪里结束以及其余文本在哪里开始。
我还创建了第二个环境,语法更简洁(恕我直言)。但它也存在同样的问题(因为它会产生相同的输出)。
\documentclass[]{article}
\usepackage{duckuments}
\newdimen\dialogunskip
\newenvironment{Dialog}
{%
\dialogunskip=-\parskip
\setlength\parskip{0pt}%
\setlength\parindent{1em}%
\par
}
{%
\par
\vskip\dialogunskip
}
\newenvironment{dialog}
{%
\dialogunskip=-\parskip
\newcommand*\say[1][]% optional argument to keep track of who says what
{%
\par---
\ignorespaces
}%
\parskip=0pt
\parindent=1em
}
{%
\par
\vskip\dialogunskip
}
\parindent=0pt\parskip=\baselineskip
\begin{document}
\blindduck
\begin{Dialog}
--- Which phrase should I not google under any circumstances?
--- ``Crazy LaTeX stuff''.
\end{Dialog}
\blindduck
\begin{dialog}
\say[Underduckling] Yes, I'll do as you say.
\say[Duck] Good, but hurry.
\say Who says this?
\say[Very long text] And I like to speak a lot which is why this line of
text is pretty long. In fact it is so long that it does need more than one
line. Random word: guiaendu
\end{dialog}
\blindduck
\end{document}
答案2
\vskip\baselineskip
我的意思是,您只需要在环境的开始部分添加。\parskip
在开始新段落时插入。这就是为什么第一个对话段落\parskip
之前没有可见空间的原因。
\documentclass{article}
\newenvironment{Dialog}{%
\vskip\baselineskip
\parskip=0pt
\parindent=1em
}{%
\par
\parskip=\baselineskip
\parindent=0pt
}
\parskip=\baselineskip
\parindent=0pt
\begin{document}
Some text here, now the dialog starts
\begin{Dialog}
--- Which phrase should I not google under any circumstances?
--- ``Crazy LaTeX stuff''.
\end{Dialog}
Now the text continues.
\end{document}
答案3
Dialogue
我认为创建一个环境会更简单itemize-like
:
\documentclass{article}
\usepackage{enumitem}
\newlist{Dialog}{itemize}{1}
\setlist[Dialog]{label = \textemdash, nosep}
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}
\begin{document}
Some text here, now the dialog starts
\begin{Dialog}
\item Which phrase should I not google under any circumstances?
\item ``Crazy LaTeX stuff''.
\end{Dialog}
Now the text continues.
Another paragraph with some more text
\end{document}