add tag
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

![Screen Shot 2020-10-16 at 13.59.36.png](/image?hash=a75c4138343970afcbce6d2c99a23bb3afde8db4bea09bd6a9dbff7351c8a303)

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}
```

![Screen Shot 2020-10-16 at 14.19.35.png](/image?hash=ffc261163418b92cac84cbafaf8ebef29db8cac59f9a40df3594900b1c30620b)
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}
```
![Screen Shot 2020-10-16 at 6.29.39 AM.png](/image?hash=9c259192f86b9e7b31bbcdb3eee35cbdf0de0df9bb8c5f0e8a732edd44876ad3)

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.