3
\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?

  • 1
    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? – TeXnician Jan 22 '18 at 14:09
  • 2
    Try code example also on ShareLaTeX and you'll see the same effect (due to the descender of p). – egreg Jan 22 '18 at 14:11
3

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

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.