# tcolorbox: TikZ picture option of “tikz lower”?

Package tcolorbox has defined a style called "tikz lower". The package manual introduces it as follows:

/tcb/tikz lower=options

This style adds a centered tikzpicture environment to the start and end of the lower part. The options may be given as TikZ picture options.

However, I quite don't understand what it means by saying "TikZ picture options". Here's my attempt to change the scale of two axes (normally I would do \begin{tikzpicture}[x=10pt,y=20pt]):

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}
\usepackage{tikz}

\newtcblisting{displaytikz}{
tikz lower,
% tikz lower={x=10pt,y=20pt},
listing side text,
bicolor,colback=blue!30!white,colbacklower=white,
colframe=black,righthand width=3cm
}

\begin{document}

\begin{displaytikz}
\draw (0,0) -- (1,1);
\draw (0,0.5) -- (2,0);
\end{displaytikz}

\end{document}


I replace the first line in my \newtcblisting definition by the commented second line, then I get an error:

Package pgfkeys Error: I do not know the key '/tcb/y', to which you passed '20pt]', and I am going to ignore it. Perhaps you misspelled it. \begin{displaytikz}

FYI, I also check the tcolorbox.sty, the relevant line is:

...
tikz lower/.style={
before lower=\centering\tcb@shield@externalize\begin{tikzpicture}[#1],
after lower=\end{tikzpicture}
}, ...


I think I must have mistaken something. If tikz lower is not for this, then how can I convey arguments to the TikZ environment? Any ideas?

I can confirm the problem, but this exists not only with x and y options but with every second option you can include in tikz lower. I don't know how to solve it.

As a workaround you can define a TikZ style and use it as option for tikz lower.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}
\usepackage{tikz}

\tikzset{
mystyle/.style={x=10pt, y=20pt, red, line width=2pt}}

\newtcblisting{displaytikz}{
tikz lower={mystyle},
listing side text,
bicolor,colback=blue!30!white,colbacklower=white,
colframe=black,righthand width=3cm
}

\begin{document}

\begin{displaytikz}
\draw (0,0) -- (1,1);
\draw (0,0.5) -- (2,0);
\end{displaytikz}

\end{document}


• Exactly, no option works. It's weird that the manual says something in that way. Thank you for your brilliant trick and I think your answer is probably what the package expects users to do. – wklchris Mar 26 '18 at 10:40
• @wklchris I've reported this issue on tcolorbox development place. – Ignasi Mar 26 '18 at 10:48
• Maybe, you would like to modify your answer with the patch? Thank you for reporting this issue. – Thomas F. Sturm Mar 27 '18 at 10:45
• @ThomasF.Sturm (I'm the questioner) Thank you for your quick response to the issue. Though the answerer has not gone online, I've tested the patch and it works well. Issue here: github.com/T-F-S/tcolorbox/issues/40 – wklchris Mar 27 '18 at 10:59

Thanks to @ThomasF.Sturm (the developer of tcolorbox package) and @Ignasi (the answerer above, who reported the issue), here's a ME that passes:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins,xparse}
\usepackage{tikz}

% Patch start
\makeatletter
\tcbset{
tikz upper/.style={before upper=\centering\tcb@shield@externalize\begin{tikzpicture}[{#1}],after upper=\end{tikzpicture}},%
tikz lower/.style={before lower=\centering\tcb@shield@externalize\begin{tikzpicture}[{#1}],after lower=\end{tikzpicture}},%
}
\makeatother

\NewTCBListing{displaytikz}{ O{} }{
tikz lower={#1},
listing side text,
bicolor,colback=blue!30!white,colbacklower=white,
colframe=black,righthand width=3cm
}

\begin{document}

\begin{displaytikz}
\draw (0,0) -- (1,1);
\draw (0,0.5) -- (2,0);
\end{displaytikz}

\begin{displaytikz}[x=10pt, y=20pt, red, line width=2pt]
\draw (0,0) -- (1,1);
\draw (0,0.5) -- (2,0);
\end{displaytikz}

\end{document}