1

How do I add a background color to the following?

\begin{lstlisting}

{
  "client_id": "string",
  "api_key": "string",
}
\end{lstlisting}
1
2

You can use \lstset{...} to change settings on your listing; in this case, you want to change the backgroundcolor setting. The xcolor package provides colors you can use.

\documentclass{article}

\usepackage{xcolor}

\lstset{backgroundcolor=\color{blue}}

\begin{document}
\begin{lstlisting}

{
      "client_id": "string",
        "api_key": "string",
}
\end{lstlisting}
\begin{document}

Additionally, you can define your own colors using the \definecolor macro. For example, to use hex color codes, you could use \definecolors{lightblue}{HTML}{0088FF}, and then reference the color lightblue in your background color setting.

For more information on colors, the LaTeX Wikibook has a more in-depth description.

0

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.