# tikzexample code line auto wrap in beamer

In beamer, if we demo some code with tkzexample package (refer to this example),sometimes code will run out of the frame box.

1. Is it possible to make it auto wrap if code line too long?
2. The distance between 2nd and 3rd diagram seems not equal.

example code:

\documentclass[t]{beamer}
\usepackage{tikz}
\usepackage{tkzexample}

\colorlet{graphicbackground}{red!10!white}%
\colorlet{codebackground}{blue!10!white}%
\colorlet{codeonlybackground}{blue!10!white}

\begin{document}
\begin{frame}[fragile]{tikz example}
\begin{tkzexample}[width=2cm]
\begin{tikzpicture}
\draw (0,0)  node[circle,
ball color=orange,
minimum size=2cm]{};
\end{tikzpicture}
\end{tkzexample}

\begin{tkzltxexample}[line frame width=0pt]
\begin{tkzexample}[width=1cm]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{tkzltxexample}

\begin{tkzexample}[width=1.7cm]
\tikz[baseline]
\node [circle,line width=1ex,draw=blue,fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{frame}

\end{document}


Output:

If you don't mind to change to tcolorbox package instead of tkzexample you can do something like:

tcolorbox uses listings (or minted) for code typesetting and all their options (font style, line numbering, breaking lines, ...) can be applied to listing parts. I've looked at tkzexample and I think it doesn't uses it.

At the moment I don't know how to add a background color to TiKZ figures. We'll I know, change text outside listing with text side listing but in this case there is no separation between code and result boxes.

\documentclass[t]{beamer}
\usepackage{tikz}
\usepackage[most]{tcolorbox}

\newtcblisting{tkzexample}[1][]{text outside listing, fonttitle=\bfseries, bicolor, colback=blue!10!white, colbacklower=red!10!white, colframe=black, sharp corners, frame hidden, size=tight, #1}

\newtcblisting{tkzltxexample}[1][]{listing only, fonttitle=\bfseries, bicolor, colback=blue!10!white,colbacklower=red!10!white, colframe=black, sharp corners, frame hidden, size=tight, #1}

\begin{document}
\begin{frame}[fragile]{tikz example}
\begin{tkzexample}[lefthand width=2cm]
\begin{tikzpicture}
\draw (0,0) node[circle,
ball color=orange,
minimum size=2cm]{};
\end{tikzpicture}
\end{tkzexample}

\begin{tkzltxexample}[listing only]
\begin{tkzexample}[width=1cm]
\tikz[baseline]
\node [circle, line width=1ex, draw=blue, fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{tkzltxexample}
%

\begin{tkzexample}[lefthand width=1.5cm]
\tikz[baseline]
\node [circle, line width=1ex, draw=blue, fill=blue]
{\textcolor{white}{\Large{TikZ}}};
\end{tkzexample}
\end{frame}

\end{document}

• It seems my tcolorbox is v3.04 so this example cannot pass build. then I try to download v3.40 from official site and copy it to /usr/local/texlive/2014/texmf-dist/tex/latex/tcolorbox, but it still can not pass build. error message is: I can't find file tcbraster.code.tex'. But I see this file in the directory actually. :-) – Beatlej Feb 17 '15 at 15:46
• @Beatlej I use MiKTeX and not texlive, but I think you need to update package's database. If you installed by hand try with tlmgr` I think it does all the work for you. – Ignasi Feb 17 '15 at 16:00
• Exactly,I need run below two command:tlmgr update --self, then run: tlmgr install tcolorbox, everything works fine now. – Beatlej Feb 17 '15 at 16:13