我无法在我的语法环境中添加标题和标签:
\documentclass{article}
\usepackage{syntax}
\grammarindent 80pt
\begin{document}
\begin{grammar}
<condition> ::= "$" <element> "$ = " <value>
<element> ::= <field> \alt <property>
\end{grammar}
\end{document}
答案1
该环境不是浮动环境,因此不能有标题,也不能通过和{grammar}
引用。据我所知,该包也没有提供浮动等效项。\label
\ref
syntax
不过,你可以定义自己的浮动环境。有许多软件包可以帮助完成这项任务,其中之一是newfloat
(与caption
包 - 它们来自同一作者)。
\documentclass{article}
\usepackage{newfloat}
\usepackage{syntax}
% declare the floating environment {Grammar}
% this will also define \listofGrammars:
\DeclareFloatingEnvironment[
% the file extension for the file used to create the list:
fileext = logr,% don't use log here!
% the heading for the list:
listname = {List of Grammars},
% the name used in captions:
name = Grammar,
% the default floating parameters if the environment is used
% without optional argument:
placement = htp
]{Grammar}
\grammarindent=80pt
\begin{document}
\begin{Grammar}
\begin{grammar}
<condition> ::= "$" <element> "$ = " <value>
<element> ::= <field> \alt <property>
\end{grammar}
\caption{A sample caption}\label{gra:sample}
\end{Grammar}
See grammar~\ref{gra:sample} ...
\end{document}