I am using the answer here to add source code to my beamer (usually inline), as:


But then some lines of code cannot fit to a single line, so I have to reduce the font size to fit.

enter image description here

Then I add a font size to the \code command like:

\newcommand{\code}[1]{\colorbox{light-gray}{\texttt{#1}[10pt]{\fontsize{#2}{#1}\selectfont #3}}}

This doesn't work. What's the correct way of doing this?


1 Answer 1


You might change the definition into


so you can call

\code{Some code to typeset}


\code[\tiny]{Some code to typeset}

Any font size changing command can be used as the optional argument. Even \fontsize{2}{0}\selectfont if you really want to make the slide unreadable. ;-)

You must log in to answer this question.

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