本地调整 gb4e {exe} 环境

本地调整 gb4e {exe} 环境

在我的论文中,我大量使用了包exe的环境gb4e,我很喜欢它。但是,我的大约 100 个示例中有三个需要有替代布局。与通常的设计不同,我需要这三个示例的第二行和以下行从环境的左括号开始exe。因此,理想情况下,在 (1) 中韋斯特线和(2)中的韋斯特光盘文件系统行从左括号开始的位置开始。有人知道如何在本地生成此变体吗?

在此处输入图片描述

这是使用以下代码创建的:

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e}

\begin{document}

\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}
\end{document}

编者注:正如 Alan Munn 在评论中强调的那样,语言学中的编号是从 1 开始的。因此,命令/环境需要根据其位置进行编号。它必须对前面的示例敏感,并且后面的示例需要对命令/环境敏感。

答案1

gb4e将环境设置exe为常规的list。此外,每个\ex宏默认为\item(如果您未指定可选参数)。因此,您可以使用enumitem来模拟显示,同时根据需要设置一些其他属性。

以下 MWE 正是这样做的(我从中获取了列表参数g4be.sty),并提供myexe替代方案:

在此处输入图片描述

\documentclass{article}
\usepackage{gb4e,enumitem,calc}% http://ctan.org/pkg/{gb4e,enumitem,calc}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newlist{myexe}{enumerate}{1}
\setlist[myexe]{
  label=(\arabic*),
  labelindent=*,
  leftmargin=1em,
  labelwidth=\widthof{(234)},
  labelsep=1em,
  itemindent=\labelindent+\labelwidth,
  topsep=7pt plus 2pt minus 3pt,
  itemsep=3pt plus 2pt,
  listparindent=0pt,
  parsep=1pt plus.5pt minus.5pt
  }
\makeatletter
\let\c@myexei\c@exx% http://tex.stackexchange.com/q/33898/5764
\patchcmd{\enit@enumerate@i}% <cmd>
  {\usecounter\@enumctr}% <search>
  {\@nmbrlisttrue\def\@listctr{\@enumctr}}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}

Original \verb|exe| environment:

\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf% ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

Updated \verb|myexe| environment:

\begin{myexe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{myexe}

\end{document}

etoolbox补丁(要放置myexe需要定义(define )来使其与所使用的myexe其余环境相适应,并允许对每个示例进行连续编号。exegb4e

\newlist{<list>}{<type>}{<depth>}创建一个类型为 且深度<list>为 的列表,几乎就像克隆列表一样。为列表设置全局选项,避免在每次使用时都进行本地设置,例如<type><depth>\setlist{<list>}{<options>}<list>

\begin{myexe}[<options>]
  %...
\end{myexe}

有关全局列表设置的更多信息,请参阅部分5 全局设置(第 9 页)enumitem文档

答案2

与沃纳的方法完全不同。

加载calc包并添加

\makeatletter
\def\myex{\setlength{\parindent}{-\leftmargin+\labelsep}\@ifnextchar [{\@ex}{\item}}
\makeatother

在序言中。

然后在需要特殊布局的环境\myex中使用新定义的,例如exe

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e,calc}

\makeatletter
\def\myex{\setlength{\parindent}{-\leftmargin+\labelsep}\@ifnextchar [{\@ex}{\item}}
\makeatother

\begin{document}

\noindent Usual layout: 
\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\noindent Modified layout:
\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}
\end{document} 

输出:

在此处输入图片描述

否则,您只需添加一行

\setlength{\parindent}{-\leftmargin+\labelsep}

就在\begin{exe}您需要特殊布局之后。


当然,采用这种方法,第九个之后的项目将看起来像

在此处输入图片描述

如果您不喜欢这种行为,您可以将上面的代码替换\makeatletter\makeatother以下代码:

\newlength{\digitlen}
\settowidth{\digitlen}{1}

\makeatletter
\def\myex{%
\ifnum\thexnumi>8%
  \ifnum\thexnumi>98%
    \setlength{\parindent}{-\leftmargin+\labelsep-2\digitlen}%
  \else%
    \setlength{\parindent}{-\leftmargin+\labelsep-\digitlen}%
  \fi%
\else%
  \setlength{\parindent}{-\leftmargin+\labelsep}%
\fi%
\@ifnextchar [{\@ex}{\item}}
\makeatother

因此,以下 MWE

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e,calc}

\newlength{\digitlen}
\settowidth{\digitlen}{1}

\makeatletter
\def\myex{%
\ifnum\thexnumi>8%
  \ifnum\thexnumi>98%
    \setlength{\parindent}{-\leftmargin+\labelsep-2\digitlen}%
  \else%
    \setlength{\parindent}{-\leftmargin+\labelsep-\digitlen}%
  \fi%
\else%
  \setlength{\parindent}{-\leftmargin+\labelsep}%
\fi%
\@ifnextchar [{\@ex}{\item}}
\makeatother

\begin{document}

\setcounter{exx}{8}

\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\setcounter{exx}{98}

\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\end{document} 

产量

在此处输入图片描述

相关内容