# \colorbox height too long

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{minted}
\usepackage{parskip}

\definecolor{codegray}{gray}{0.9}
\newcommand{\code}[1]{\colorbox{codegray}{\texttt{#1}}}

\begin{document}

\code{test code}\\
anotherline

\end{document}


This is working good on sharelatex.com and looks like I expect and want it:

but on my local project using this command gives me this:

any idea what could be causing this colorbox height going to the next line?

• Well, why are you not posting the local project content then?
– user31729
Jan 22 '18 at 14:07
• Do you mean that the depth is too big? So that you want letters like g, p and q to be treated different than l, h, t which expand to top rather than bottom? Jan 22 '18 at 14:09
• Try code example also on ShareLaTeX and you'll see the same effect (due to the descender of p). Jan 22 '18 at 14:11

The difference is due to the fact that test code has no descender, whereas example has.

\documentclass{article}
\usepackage{xcolor}

\definecolor{codegray}{gray}{0.9}
\newcommand{\code}[1]{%
\begingroup\setlength{\fboxsep}{1pt}%
\colorbox{codegray}{\texttt{\hspace*{2pt}\vphantom{Ay}#1\hspace*{2pt}}}%
\endgroup
}

\begin{document}

\noindent
\code{test code} \code{example code}\\
C\# test \& this

\noindent
\code{example code} \code{test code}\\
C\# test \& this

\end{document}