topnush
I have this MWE for typesetting Python:

```
\documentclass[11pt]{beamer}

\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
	numbers=none, 
	numberstyle=\small, 
	numbersep=8pt, 
	language=Python
}


\newtcblisting{mylisting}[2][]{
	arc=0pt, outer arc=0pt,
	listing only, 
	listing style=mystyle,
	title=#2,
	#1
}

\usepackage{listings,newtxtt}

\lstset{basicstyle=\ttfamily, keywordstyle=\bfseries}


\begin{document}




\begin{frame}[fragile]
	\begin{mylisting}[hbox]{}
def foo():
   return ValueError("Invalid input.")		
	\end{mylisting}


\end{frame}

\end{document}
```

![Screenshot from 2024-02-21 16-26-46.png](/image?hash=06439eacf7262e45204abc216f85dd160a17f0564dbb855cae80b19e2d8a6cb5)

Unfortunately the frame around the code goes over the righthand margin. How can I set its width to stop this?
Top Answer
samcarter
The problem is that your code is wider than the text width. There are several tabs at the end which make the code much wider than it looks.

If you use the `hbox` option, your box will adapt to the width of the content and thus make the box wider than the frame.

If you don't want this, remove the `hbox` and the box will span the whole text width, but not more:

```
\documentclass[11pt]{beamer}

\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
	numbers=none, 
	numberstyle=\small, 
	numbersep=8pt, 
	language=Python
}


\newtcblisting{mylisting}[2][]{
	arc=0pt, outer arc=0pt,
	listing only, 
	listing style=mystyle,
	title=#2,
	#1
}

\usepackage{listings,newtxtt}

\lstset{basicstyle=\ttfamily, keywordstyle=\bfseries}


\begin{document}




\begin{frame}[fragile]
	\begin{mylisting}[]{}
def foo():
   return ValueError("Invalid input.")
	\end{mylisting}


\end{frame}

\end{document}
```

![document-1.png](/image?hash=9b0d5012af272cf1b3f5333597caebdb1a6c63018e7fe9690fb1c34593a5e5ad)

---

If you prefer your hbox, you will have to ensure yourself that the content fits on the page by removing all the tabs at the end of listings:

```
\documentclass[11pt]{beamer}

\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
	numbers=none, 
	numberstyle=\small, 
	numbersep=8pt, 
	language=Python
}


\newtcblisting{mylisting}[2][]{
	arc=0pt, outer arc=0pt,
	listing only, 
	listing style=mystyle,
	title=#2,
	#1
}

\usepackage{listings,newtxtt}

\lstset{basicstyle=\ttfamily, keywordstyle=\bfseries}


\begin{document}




\begin{frame}[fragile]
	\begin{mylisting}[hbox]{}
def foo():
   return ValueError("Invalid input.")
	\end{mylisting}


\end{frame}

\end{document}
```

![document-1.png](/image?hash=94e157417f87cec21a3062b21733417d1ea420eae4f40f29ffe9d56d2193c51a)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.