I love the way StackExchange formats inline code, using both a fixed width font and a gray background.
How can I mimic the above sentence in LaTeX?
One possibility might be using a combination of the listings, helvet, and inconsolata packages (in addition to the geometry package). Here is an attempt:
\documentclass{article}
% Implement 1-inch margins using 'geometry' package
% ('geometry' package: https://ctan.org/pkg/geometry)
\usepackage[margin=1in]{geometry}
% Implement inline code using 'listings' package
% ('listings' package: https://ctan.org/pkg/listings)
\usepackage{listings}
% Implement Helvetica using 'helvet' package
% ('helvet' package: https://ctan.org/pkg/helvet)
% (use code snippet from https://tex.stackexchange.com/a/121063/15622/)
\usepackage[scaled]{helvet}
\renewcommand\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
% Implement Inconsolata, a Consolas-like font, using 'inconsolata' package
% ('inconsolata' package: https://ctan.org/pkg/inconsolata)
\usepackage{inconsolata}
\lstset{basicstyle=\ttfamily}
\begin{document}
\section*{Attempt to mimic StackExchange inline code}
\noindent I love the way StackExchange \lstinline|formats inline code|,
using both a \lstinline|fixed width font| and \lstinline|a gray background|.
\end{document}
However, I'm not sure how to obtain the gray background. How can I do this?
In what other ways can my attempt be improved to mimic StackExchange-style inline code?







\lstinlnedoes not support frames or background colors. – Stephen Nov 14 '23 at 05:21