3

Driven from Let's get fancy: Text like tag? , I wrote this code:

\documentclass{article}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
\mybox{C{}\verb!++!}
\end{document}

The error:

! Missing } inserted.
<inserted text>
}
l.9 \mybox{C{}\verb!++!}

This works with normal text inside the box, but because of the fancy way I am trying to write C++ and the fancy textbox, I am getting fancy² and I overflow! :) Any ideas?

  • You can't use verbatim code like this in the command argument of tcbox – user31729 May 28 '16 at 14:45
  • The error I get from that code is ! LaTeX Error: \verb illegal in command argument.. – Torbjørn T. May 28 '16 at 14:47
  • Oh damn, any workaround @ChristianHupfer to keep tcbox and still have a fancy C++ text? – gsamaras May 28 '16 at 14:47
  • \tcboxverb is what you want – user31729 May 28 '16 at 14:47
4

You can use \texttt{++} instead, can't you?

enter image description here

\documentclass{article}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
\mybox{C\texttt{++}}
\end{document}
  • This works. Christian's solution should work for newer installations than mine's! – gsamaras May 28 '16 at 14:54
4

I hope, at least this compiles for the O.P. ;-)

\tcboxverb is designed for such small boxes with verbatim content.

I've added a myboxstyle TikZ style for this.

\documentclass{article}
\usepackage[most]{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

%\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
%  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\tcbset{myboxstyle/.style={%
nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base
}}

\begin{document}
\tcboxverb[myboxstyle]{C++}

\tcboxverb[myboxstyle]{#include <iostream>}
\end{document}

enter image description here

  • l.14 \tcboxverb gets an undefined control sequence. You can't escape your faith Christian. Danke! – gsamaras May 28 '16 at 14:53

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.