Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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:

\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}}
share|improve this answer
add comment

Your Answer

 
discard

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.