但有时我喜欢使用标题部分来表示代码或命令或某种输入,并在底部显示输出,如下所示:
问题在于排版(没有等宽字体、奇怪的引号等),没有语法高亮,LaTeX 解释各种命令和特殊字符(例如$
,,,,,,&
),#
尝试使用^
是有问题的()。_
\\
\verb
LaTeX Error: \verb illegal in command argument.
有什么想法吗?谢谢。以下是代码:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
答案1
listing and comment
这是使用和框的可能解决方案bicolor
。上面的框显示列表,下面的框comment
显示预期结果。
该overlay
线试图模仿带有标题和上部的常规 tcolorbox 的几何形状。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%