5

I have a chunk of code in an alltt environment and I want to highlight elements that are auto-generated (two colours for different methods):

\newcommand{\gen}[1]{\colorbox{DGray}{#1}}
\newcommand{\tpl}[1]{\colorbox{Gray}{#1}}

\begin{alltt}
\gen{class }\tpl{Something}...
\end{alltt}

My problem is that the frame around 'Something' is taller than the one around 'class ' and reaches lower due to the letter 'g', so the two frames aren't aligned. Is there a way to make a shading frame with a fixed height and position? Basically, I want shading the OpenOffice/MS Office way.

4

You can use \strut:

\newcommand{\gen}[1]{\colorbox{DGray}{\strut #1}}
\newcommand{\tpl}[1]{\colorbox{Gray}{\strut #1}}

or a \vphantom with some appropriate letters:

\newcommand{\gen}[1]{\colorbox{DGray}{\vphantom{Ag}#1}}
\newcommand{\tpl}[1]{\colorbox{Gray}{\vphantom{Ag}#1}}

or, to have even finer control, a \rule with the desired height and depth, and zero width:

\newcommand{\gen}[1]{\colorbox{DGray}{\rule[-6pt]{0pt}{16pt}#1}}
\newcommand{\tpl}[1]{\colorbox{Gray}{\rule[-6pt]{0pt}{16pt}#1}}
| 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.