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?

  • 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 Sep 26 '13 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. – Dušan Rychnovský Sep 26 '13 at 10:45
4

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.