5

I have a quite long but narrow code I want to typeset inside a tcolorbox. Is it possible to enable a two (or more) column mode inside the box (not break the box and set the parts adjacent). The remaining part of the document is single-column. If possible I would like it to still be floatable if enabled, it doesn't need to be breakable.

EDIT: it seems not to be enough to escape \tcblower from the minted part. I tried it with the listings package and it just broke the layout.

\documentclass{report}
\usepackage{tcolorbox}
\tcbuselibrary{minted}
\usepackage{blindtext}
\begin{document}
\blindtext
\begin{tcblisting}{title=This is source code in another language (XML),
minted language=XML,listing only}
<project 
    name="Package tcolorbox" 
    default="documentation" 
    basedir="."
    >
</project>
<project 
    name="Package tcolorbox" 
    default="documentation" 
    basedir="."
    >
</project>
<project 
    name="Package tcolorbox" 
    default="documentation" 
    basedir="."
    >
</project>
\end{tcblisting}
\blindtext
\end{document}
3
  • Presuming the lines lengths are the same for every line, is there anything wrong with splitting the code manually and just putting two boxes in a listings/minted environment side by side? Or are you looking for a less manual solution? Jan 30, 2015 at 12:12
  • I would like to still have it in a single tcblisting-box and referenced as a single listing. My current solution are two tcblistings side by side in miniboxes broken by hand. But I don't really like that solution.
    – Juri Robl
    Jan 30, 2015 at 12:15
  • I would obviously prefer a completely automatic solution, but would use a manual too. I don't have that many listings of that kind.
    – Juri Robl
    Jan 30, 2015 at 12:16

1 Answer 1

6

It's not perfect (I personally don't like how the code cuts mid tag) but it should do the job.

Basically, I unpacked the tcblisting environment and added a multicols environment.

\documentclass{report}
\usepackage{tcolorbox}
\tcbuselibrary{minted}
\usepackage{blindtext}
\usepackage{multicol} % added package
\begin{document}
\blindtext
\begin{tcolorbox}[title=This is source code in another language (XML)]
  %add special color box to list of listings
  \makeatletter
  \addcontentsline{lol}{subsection}{\kvtcb@title}
  \makeatother

  \begin{multicols}{2}
    \begin{minted}{xml}

      <project 
      name="Package tcolorbox" 
      default="documentation" 
      basedir="."
      >
      </project>
      <project 
      name="Package tcolorbox" 
      default="documentation" 
      basedir="."
      >
      </project>
      <project 
      name="Package tcolorbox" 
      default="documentation" 
      basedir="."
      >
      </project>
    \end{minted}
  \end{multicols}
\end{tcolorbox}
\blindtext
\end{document}

Example of previous code output.

4
  • Of course! Why didn't I think of that. Works great! I defined a new newtcolorbox and copied the formating from my normal newtcblisting and used it's counter with use counter from.
    – Juri Robl
    Jan 30, 2015 at 12:59
  • The one drawback of this approach is that it doesn't come up in list of listings properly (since the title is not a caption), is that a problem? Jan 30, 2015 at 13:01
  • Nope, that works with the option addtolol from here I am already using.
    – Juri Robl
    Jan 30, 2015 at 13:05
  • That's nice! Updated my answer to include addtolol. Jan 30, 2015 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .