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):


\gen{class }\tpl{Something}...

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.


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:


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

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