topnush
Take this code:
```
\documentclass{beamer}
\usepackage[many]{tcolorbox}
\usepackage{listings}
\lstdefinestyle{duckstyle}{%
moredelim=[is][\color{red}]{|}{|},
mathescape=true,
escapechar=@,
basicstyle=\ttfamily,
columns=fullflexible
}
\lstset{style=duckstyle}
\tcbuselibrary{skins}
\tcbset{
colback=white
}
\begin{document}
\begin{frame}[fragile]
\begin{tcolorbox}[top=0pt, left=5pt,right=5pt, colback=blue!5!white, text height=0.5cm]
\begin{lstlisting}[ mathescape, name=countsketchshort, basewidth = {.3em}]
return $\hat{f}_{a_i} =$ median{$g_j(a_i) C[j, h_j(a_i)]$}
\end{lstlisting}
\end{tcolorbox}
\end{frame}
\end{document}
```
How can I reduce the space between the text in the box and the top of the box? I tried playing with top but it doesn't seem to do what I expected.
Top Answer
samcarter
The space comes from the top of the listing

As quick hack, I'd just insert a bit of negative vertical space:
```
\documentclass{beamer}
\usepackage[many]{tcolorbox}
\usepackage{listings}
\lstdefinestyle{duckstyle}{%
moredelim=[is][\color{red}]{|}{|},
mathescape=true,
escapechar=@,
basicstyle=\ttfamily,
columns=fullflexible
}
\lstset{style=duckstyle}
\tcbuselibrary{skins}
\tcbset{
colback=white
}
\begin{document}
\begin{frame}[fragile]
\begin{tcolorbox}[top=0pt, left=5pt,right=5pt, colback=blue!5!white, text height=0.5cm]
\vskip-0.1cm
\begin{lstlisting}[ mathescape, name=countsketchshort, basewidth = {.3em}]
return $\hat{f}_{a_i} =$ median{$g_j(a_i) C[j, h_j(a_i)]$}
\end{lstlisting}
\end{tcolorbox}
\end{frame}
\end{document}
```

Answer #2
user 3.14159
You could use the `listings` library of `tcolorbox`. (There are a number of cool features for those.)
```
\documentclass{beamer}
\usepackage[many,listings]{tcolorbox}
\lstdefinestyle{duckstyle}{%
moredelim=[is][\color{red}]{|}{|},
mathescape=true,
escapechar=@,
basicstyle=\ttfamily,
columns=fullflexible
}
\lstset{style=duckstyle}
\tcbuselibrary{skins}
\tcbset{
colback=white
}
\begin{document}
\begin{frame}[fragile]
\frametitle{A listing}
\begin{tcblisting}{top=0pt,bottom=0pt,left=5pt,right=5pt,colback=blue!5!white,
listing only,
listing options={mathescape, name=countsketchshort, basewidth = {.3em}}}
return $\hat{f}_{a_i} =$ median{$g_j(a_i) C[j, h_j(a_i)]$}
\end{tcblisting}
\end{frame}
\end{document}
```
