TransWikia.com

Adding font size to already defined command

TeX - LaTeX Asked on December 19, 2020

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

usepackage{xcolor}
definecolor{light-gray}{gray}{0.95}
newcommand{code}[1]{colorbox{light-gray}{texttt{#1}}}

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?

One Answer

You might change the definition into

newcommand{code}[2][]{colorbox{light-gray}{texttt{#1#2}}}

so you can call

code{Some code to typeset}

or

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. ;-)

Correct answer by egreg on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP