1

I suppose it's meant to be used like this: enter image description here

But sometimes I like to use the title section to represent code or a command or some kind of input, and show the output in the bottom section like this: enter image description here The problem is the typesetting (no monospace, weird quotes, etc.), no syntax highlighting, LaTeX interprets various commands & special characters (e.g. $, &, #, ^, _, \\) and trying to use \verb is problematic (LaTeX Error: \verb illegal in command argument.).

Any ideas? Thanks. Here's the code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[margin=10,varwidth]{standalone}
\usepackage[minted,most]{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{tcolorbox}[title=\textbf{echo 'hello, world'}]
\begin{minted}{bash}
hello, world
\end{minted}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tcolorbox}[title=\textbf{hello\_world.sh}]
\begin{minted}{bash}
#!/usr/bin/env bash
echo 'hello, world'
\end{minted}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  • 2
    A less painfull approach would be utilize "upper" and "lower" part of tcolorbox (access via \tcblower); you can also have a subtitle in each box. – Tomáš Kruliš Nov 24 '19 at 17:57
  • @TomášKruliš You're right, that might be better. Would you care to demonstrate? I see a few things like what you describe in the manual, but what you describe sounds even better. – voices Nov 25 '19 at 17:14
2

This is a possible solution using a listing and comment and bicolor box. Upper box shows the listing and lower one the comment which is the expected result.

The overlay line tries to mimic the geometry of a regular tcolorbox with title and upper part.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[margin=10,varwidth]{standalone}
\usepackage[minted,most]{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{tcolorbox}[title=\textbf{echo 'hello, world'}]
\begin{minted}{bash}
hello, world
\end{minted}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tcolorbox}[title=\textbf{hello\_world.sh}]
\begin{minted}{bash}
#!/usr/bin/env bash
echo 'hello, world'
\end{minted}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tcblisting}{notitle, 
    listing and comment,
    bicolor,
    colback=black!75!white,
    colbacklower=black!5!white,
    top=0mm, middle=1mm,
    overlay={\draw[line width=1.05mm, black!5!white, opacity=1] ([shift={(.5mm,1mm)}]frame.west)--([shift={(-.5mm,1mm)}]frame.east);},
    comment={hello, world}, 
    colupper=white,
    fontlower=\ttfamily,}
echo 'hello, world'
\end{tcblisting}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

enter image description here

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.