5
\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: enter image description here

but on my local project using this command gives me this: enter image description here

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

3
  • 1
    Well, why are you not posting the local project content then?
    – user31729
    Jan 22, 2018 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?
    – TeXnician
    Jan 22, 2018 at 14:09
  • 3
    Try code example also on ShareLaTeX and you'll see the same effect (due to the descender of p).
    – egreg
    Jan 22, 2018 at 14:11

1 Answer 1

4

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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .