以下代码取自源和输出并排
\documentclass{article}
\usepackage[skins,listings]{tcolorbox}
\newtcblisting{exampleB}[2][]{%
colframe=red!50!yellow!50!black,
colback=white,
coltitle=red!50!yellow!3!white,
bicolor,colbacklower=red!50!yellow!5!white,
fonttitle=\sffamily\bfseries,
sidebyside,text and listing,
title=#2,#1}
\newenvironment{cExample}{\begin{exampleB}[lefthand width=3.5cm,text outside listing, colback=red!50!yellow!5!white,top=0mm,bottom=0mm,left=0mm,right=0mm,
arc=0mm,boxrule=1pt,watermark text=Source,
watermark color=yellow!75!red!30!white]{}}{\end{exampleB}}
\let\baExample\exampleB
\let\eaExample\endexampleB
\newenvironment{aExample} {\baExample[lefthand width=3.5cm,text outside listing,
colback=red!50!yellow!5!white,top=0mm,bottom=0mm,left=0mm,right=0mm,
arc=0mm,boxrule=1pt,watermark text=Source,
watermark color=yellow!75!red!30!white]{}} {\eaExample}
\begin{document}
\begin{aExample}
\begin{tikzpicture}
\path[fill=yellow!50!white] (0,0) circle (11mm);
\path[fill=white] (0,0) circle (9mm);
\foreach \w/\c in {90/red,210/green,330/blue}
{\path[shading=ball,ball color=\c] (\w:1cm) circle (7mm);}
\end{tikzpicture}
\end{aExample}
%\begin{cExample}
\begin{tikzpicture}
\path[fill=yellow!50!white] (0,0) circle (11mm);
\path[fill=white] (0,0) circle (9mm);
\foreach \w/\c in {90/red,210/green,330/blue}
{\path[shading=ball,ball color=\c] (\w:1cm) circle (7mm);}
\end{tikzpicture}
%\end{cExample}
\end{document}
环境aExample
可以正常工作,但是环境cExample
(取消注释begin/end
环境行)会引发错误
失控的争论?
!扫描使用 \next 时文件结束。
<
插入文本>
\par
答案1
环境需要verbatim
模式。使用\begin{exampleB}
和\end{exampleB}
会使解析器混淆。只需使用\exampleB
和\endexampleB
(这本质上就是您在中所做的)aExample
。
\documentclass{article}
\usepackage[skins,listings]{tcolorbox}
\newtcblisting{exampleB}[2][]{%
colframe=red!50!yellow!50!black,
colback=white,
coltitle=red!50!yellow!3!white,
bicolor,colbacklower=red!50!yellow!5!white,
fonttitle=\sffamily\bfseries,
sidebyside,text and listing,
title=#2,#1}
\newenvironment{cExample}{%
\exampleB[
lefthand width=3.5cm,
text outside listing,
colback=red!50!yellow!5!white,
top=0mm,
bottom=0mm,
left=0mm,
right=0mm,
arc=0mm,
boxrule=1pt,
watermark text=Source,
watermark color=yellow!75!red!30!white
]{}%
}{\endexampleB}
\begin{document}
\begin{cExample}
\begin{tikzpicture}
\path[fill=yellow!50!white] (0,0) circle (11mm);
\path[fill=white] (0,0) circle (9mm);
\foreach \w/\c in {90/red,210/green,330/blue}
{\path[shading=ball,ball color=\c] (\w:1cm) circle (7mm);}
\end{tikzpicture}
\end{cExample}
\end{document}