我想写一本枫叶书,请参阅该书中的示例代码:
\documentclass{article}
\usepackage{tcolorbox,fancyvrb}
\tcbuselibrary{skins,breakable}
%-------------------------------------------------- Code Environment
\newenvironment{code}
{\VerbatimEnvironment
\begin{tcolorbox}[
breakable,
colback=red!5!white,
colframe=red!75!black,
]%
\begin{Verbatim}}
{\end{Verbatim}\end{tcolorbox}}
\newenvironment{outc}
{\begin{tcolorbox}[
breakable,
left=0mm,right=0mm,top=0mm,bottom=0mm,
% boxsep=0mm,
colback=white,
coltext=blue,
colframe=gray!50,
]}%
{\end{tcolorbox}}
%\newenvironment{outcode}
% {\begin{outc}\begin{equation}}
% {\end{equation}\end{outc}}
\newenvironment{outcode}
{\begin{outc}\[}
{\]\end{outc}}
%-------------------------------------------------- Code Environment
\begin{document}
In this example, we see too much space between this two environment \textbf{code} and \textbf{outcode}:
\begin{code}
> 2+3;
\end{code}
\begin{outcode}
5
\end{outcode}
\end{document}
输出为:
问题是:我怎样才能在 maple 代码下方写入两种不同颜色的背景和文本输出,并使用例如 tcolorbox 中的 \tcblower 命令将它们分开?
在 tcolorbox-example.tex 文件中c:\texlive\2013\texmf-dist\doc\latex\tcolorbox文件夹,使用环境技術清單对于设置,框显示源代码并在下面的其他部分显示输出,如下所示:
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black}
This is a \LaTeX\ example:
\begin{equation}
\sum\limits_{i=1}^n i = \frac{n(n+1)}{2}.
\end{equation}
\end{tcblisting}
输出为:
答案1
不要使用两个单独的tcolorboxe
s,而只需使用一个带有listing and comment
选项的 s;这样,框的上部将用于列表,下部将用于“注释”,注释几乎可以是任何内容,特别是代码的输出;皮肤bicolor
允许您独立控制两个部分(上部和下部)的颜色:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\newtcblisting{codeoutput}[1]{
breakable,
listing and comment,
bicolor,
lower separated=true,
colback=red!5,
colframe=red!75!black,
colbacklower=white,
collower=blue,
comment=#1,
overlay={
\draw[dashed,red!80!black] (segmentation.west)--(segmentation.east);
},
listing options={
language={Matlab},
aboveskip=0pt,
belowskip=0pt,
basicstyle=\ttfamily,
}
}
\begin{document}
\begin{codeoutput}{5}
> 2+3; nnnnn
\end{codeoutput}
\end{document}
另外一个选择:
\documentclass[dvipsnames]{article}
\usepackage[T1]{fontenc}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\newtcblisting{codeoutput}[1]{
breakable,
listing and comment,
bicolor,
frame style={
draw=black,
color=Maroon
},
colback=black,
colbacklower=Dandelion!15,
colupper=white,
collower=Maroon,
comment=#1,
listing options={
language={Matlab},
aboveskip=0pt,
belowskip=0pt,
basicstyle=\ttfamily,
}
}
\begin{document}
\begin{codeoutput}{5}
> 2+3; nnnnn
\end{codeoutput}
\end{document}