0

The following gives many strange errors:

\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}

including "Missing $ inserted", "Double subscript", so verbatim isn't working. Without tcolorbox the code works fine. How can I use verbatim with tcolorbox?

  • 4
    For those of us who may not be very familiar with tcolorbox, can you include a complete document (starting with \documentclass and ending with \end{document})? For example, with some experimentation I was able to reproduce your error with \usepackage{tcolorbox} \tcbuselibrary{fitting} \tcbuselibrary{skins} but I don't know if you did the same things. – ShreevatsaR Feb 7 '18 at 2:45
  • 1
    Please also provide the full and exact text of the error message you get when compiling the (completed) code you provide. This will include, for example, the line number corresponding to the relevant line in your example. – cfr Feb 7 '18 at 2:48
  • 1
    Section '7 Saving and Loading of Verbatim Texts'. Page 126 of tcolorbox's manual. 22.1 /tcb/verbatim page 423. – cfr Feb 7 '18 at 2:53
3

It runs. I hope the options are what you intended.

\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}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.