2

I have a grammar declaration like this:

\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 uses a superfluously large font to render it and some lines do not even fit on the page and need to be wrapped, which has a bad impact on clarity.

How do I change font-size only for the grammar?

2
  • In my test the font size is the same as outside the environment. Can you add a complete (compilable) example that shows the problem?
    – egreg
    Commented Sep 26, 2013 at 9:02
  • It is probably the same as in the outside environment, but as both the non-terminals and the terminals are all upper-case (which means all words in fact), it appears to be bigger. I would like it to be smaller than the default font-size, then. Commented Sep 26, 2013 at 10:45

1 Answer 1

5

Use \AtBeginEnvironment from etoolbox. But, please, always add a complete example with all packages needed. I'm guessing you're using syntax, as I don't know other packages that provide a grammar environment.

\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}

Don't use the [h!] option alone for the figure environment. You're basically telling LaTeX to run out of space if one of the figures can't be placed where you'd like it to be.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .