我想创建自定义列表环境,既可以在正文中工作,也可以在我自己引用的文本中工作(在我的例子中,我调用的环境dialogue
(list
)位于我调用的环境myquotation
(trivlist
)内)。但我无法获得预期的缩进。我的工作示例:
\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=11cm]{geometry}
\usepackage{ifthen}
% quotes
\newenvironment{myquotation}
{\begin{trivlist}
\ifthenelse{\isodd{1}}
{\setlength\leftskip{6.5mm} \setlength\rightskip{0mm}}
{\setlength\leftskip{0mm} \setlength\rightskip{6.5mm}}
\setlength\itemindent{\parindent}
\item\relax \slshape}
{\end{trivlist}}
% dialogues
\newcommand{\entrylabel}[1]{
\ifthenelse{\equal{}{#1}}{
\hfill\mbox{\small{\textsc{--}}}
}{
\mbox{\small{\textsc{#1:}}}
}
}
\newenvironment{dialogue}{\list{}{\renewcommand{\makelabel}{\entrylabel}
\itemsep=0cm \topsep=0cm \parsep=0cm
\listparindent=0em}
}{\endlist}
\begin{document}
Dialogue inside the quotation (unwanted indentation of the first item):
\begin{myquotation}
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\end{dialogue}
Some text inside the quotation following short customized dialogue.
\end{myquotation}
Dialogue inside the quotation (solution that doesn't work by flexible
vertical distances between list items):
\begin{myquotation}
\mbox{}\vspace{-\baselineskip}
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\end{dialogue}
\end{myquotation}
Dialogue outside the quotation:
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\end{dialogue}
\end{document}
对我来说,最重要的是删除引文中第一个项目的缩进。最初,我考虑将行合并\mbox{}\vspace{-\baselineskip}
到我的列表定义中(此处称为dialogue
),但在项目之间有浮动空间以及列表周围有浮动垂直间距的情况下,它无法正常工作。
如何让后面的列表项自动移动到没有缩进文本边界的位置(如图中绿色箭头所示)?
答案1
错误的缩进是由于 trivlist 中的错误造成的\setlength\itemindent{\parindent}
。另外,如果您希望对话环境根据级别而变化,最好外部环境也是一个列表。
我不知道你想要什么垂直空格,所以我把它们全部删除了。从长远来看,使用 enumitem 包定义此类列表更好、更容易。
\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=11cm]{geometry}
\usepackage{ifthen}
% quotes
\newenvironment{myquotation}
{\list{}{%
\ifthenelse{\isodd{1}}
{\setlength\leftmargin{\parindent} \setlength\rightmargin{0mm}}
{\setlength\leftmargin{0mm} \setlength\rightmargin{6.5mm}}%
\topsep=0cm \parsep=0cm \partopsep=0pt \listparindent=0em
}
\item\relax \slshape
}%
{\endlist}
% dialogues
\newcommand{\entrylabel}[1]{%
\ifthenelse{\equal{}{#1}}{%
\hfill\mbox{\small{\textsc{--}}}%
}{%
\hspace\labelsep \mbox{\small{\textsc{#1:}}}%
}
}
\newenvironment{dialogue}{\list{}{\renewcommand{\makelabel}{\entrylabel}%
\labelwidth0cm \itemindent-\leftmargin
\topsep=0cm \parsep=0cm
\partopsep=0pt
\listparindent=0em
}}{\endlist}
\begin{document}
Dialogue inside the quotation (unwanted indentation of the first item):
\begin{myquotation}
blblbl
\end{myquotation}
\begin{myquotation}
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\item blbu
\end{dialogue}
Some text inside the quotation following short customized dialogue.
\end{myquotation}
Dialogue inside the quotation (solution that doesn't work by flexible
vertical distances between list items):
\begin{myquotation}
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\end{dialogue}
\end{myquotation}
Dialogue outside the quotation:
\begin{dialogue}
\item[Cookiemonster] Om, om, om...
\item[Roadrunner] Beep, beep, beep...
\item[Reksio] Hau, hau, hau...
\end{dialogue}
\end{document}