下面给出了许多奇怪的错误:
\begin{tcolorbox}[fit,height=5cm,blank, borderline={1pt}{-2pt},nobeforeafter]
\begin{verbatim}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{verbatim}
\end{tcolorbox}
包括“缺少 $ 插入”、“双下标”,所以verbatim
不起作用。没有tcolorbox
代码也可以正常工作。我该如何verbatim
使用tcolorbox
?
答案1
运行。我希望选项符合您的预期。
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{fitting,skins}
\usepackage{listings}
\newsavebox{\tempbox}
\begin{document}
\setbox\tempbox=\hbox{\begin{lstlisting}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{lstlisting}}
\begin{tcolorbox}[fit,height=5cm,blank, borderline={1pt}{-2pt},nobeforeafter]
\usebox\tempbox
\end{tcolorbox}
\end{document}
答案2
您可以使用listings
一种什么都没有的语言来模拟简单的逐字逐句。
\documentclass{article}
\usepackage[most]{tcolorbox}
\lstdefinelanguage{none}{}
\newtcblisting{tcbverbatim}{
fit,
height=5cm,
blank,
borderline={1pt}{-2pt},
%nobeforeafter,
listing only,
listing options={
language=none,
basicstyle=\ttfamily,
columns=flexible,
}
}
\begin{document}
\begin{tcbverbatim}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{tcbverbatim}
\end{document}
答案3
tcolorbox
有一个机制来定义成熟的颜色盒逐字环境:
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcblisting{qwr}{listing only,fit,height=5cm,blank, borderline={1pt}{-2pt},nobeforeafter}
\begin{document}
\begin{qwr}
[83 democrat / 66 republican]
| | a_b_c = y: [28 democrat / 64 republican]
\end{qwr}
\end{document}