如何更改语法声明的字体大小

如何更改语法声明的字体大小

我有一个这样的语法声明:

\documentclass[12pt,a4paper]{report}
\usepackage{syntax}
\begin{document}
...
    \begin{figure}[h!]
        \begin{grammar}
            <A> ::= `<--' <B> <C> `-->'

            <B> ::= <D>

            ...
        \end{grammar}
        \caption{A sample grammar}
        \label{fig:sample-grammar}
    \end{figure}
...
\end{document}

LaTeX 使用过大的字体来呈现,有些行甚至不适合页面而需要换行,这对清晰度产生了不良影响。

我如何仅更改语法的字体大小?

答案1

使用\AtBeginEnvironment来自etoolbox。但是,请始终添加包含所有所需软件包的完整示例。我猜您正在使用syntax,因为我不知道其他提供grammar环境的软件包。

\documentclass{article}
\usepackage{syntax,etoolbox}
\AtBeginEnvironment{grammar}{\small}
\begin{document}
Some text before and
some text before and
some text before and
some text before and
some text before and
some text before and
some text before and
some text before
\begin{figure}[!htp]
    \begin{grammar}
        <A> ::= `<--' <B> <C> `-->'

        <B> ::= <D>

    \end{grammar}
    \caption{A sample grammar}
    \label{fig:sample-grammar}
\end{figure}
\end{document}

不要[h!]单独使用该选项作为figure环境选项。如果某个图形无法放置在您想要的位置,这基本上就是在告诉 LaTeX 空间不足。

在此处输入图片描述

相关内容