I used the \lstdefinelanguage to create a formatting for some JSON blocks I'd like to add to my file, I used the one in the answer for this question:
How to improve listings display of JSON files?
So I created my own \lstdefinelanguage like so:
\lstdefinelanguage{json}{
basicstyle=\normalfont\ttfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frame=lines,
backgroundcolor=\color{background},
literate=
*{0}{{{\color{numb}0}}}{1}
{1}{{{\color{numb}1}}}{1}
{2}{{{\color{numb}2}}}{1}
{3}{{{\color{numb}3}}}{1}
{4}{{{\color{numb}4}}}{1}
{5}{{{\color{numb}5}}}{1}
{6}{{{\color{numb}6}}}{1}
{7}{{{\color{numb}7}}}{1}
{8}{{{\color{numb}8}}}{1}
{9}{{{\color{numb}9}}}{1}
{:}{{{\color{punct}{:}}}}{1}
{,}{{{\color{punct}{,}}}}{1}
{\{}{{{\color{delim}{\{}}}}{1}
{\}}{{{\color{delim}{\}}}}}{1}
{[}{{{\color{delim}{[}}}}{1}
{]}{{{\color{delim}{]}}}}{1},
}
And used it like this:
\begin{figure}[htbp]
\centering
\begin{lstlisting}[language=json][firstnumber=1]
{
"type": "auth-request",
"content": {
"user": "agentA1",
"pw": "1"
}
}
\end{lstlisting}
\caption{Example of an AUTH-REQUEST message.}
\label{fig:auth-request}
\end{figure}
This gives the following document:
So for my question, what is the best way to change the width of this listing? I'd like to make it something like 80% of the \textwidth if possible. But if I do this:
\begin{lstlisting}[language=json][firstnumber=1, linewidth=.8\textwidth]
{
"type": "auth-request",
"content": {
"user": "agentA1",
"pw": "1"
}
}
\end{lstlisting}
I get a warning, namely: Package Listings Warning: Text dropped after begin of listing. and it doesn't actually change the look of the listing in the document.
So how do I change the width of a specific listing?

\begin{lstlisting}[language=json,firstnumber=1, linewidth=.8\textwidth]? – moewe Jun 07 '20 at 15:01figure. See https://tex.stackexchange.com/q/5818/35864 – moewe Jun 07 '20 at 15:08