TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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