在下面给出的代码中,我得到了输出:
如何本地改变框的大小,以便标题““cubemaster”用法”出现在一行而不是两行上?
谢谢。
这是我的代码:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}
\usepackage{matlab-prettifier}
\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
style=Matlab-editor,
basicstyle=\ttfamily\small,
numbersep=22pt,
frame=none
}
\newtcblisting{mylisting}[2][]{
arc=0pt, outer arc=0pt,
listing only,
listing style=mystyle,
title=#2,
#1
}
\begin{document}
\begin{mylisting}[hbox,enhanced,drop shadow, right=3cm]{\bfseries{``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
\end{document}
答案1
一个以作为标题的解决方案tcolorbox
,从底层框中抓取参数。
必须明确设置该colback
选项才能获得正确的titlebox
环境背景。
最有可能的是,的skin
和title
设施tcolorbox
提供了一种更简单的方法。
\documentclass{article}
\usepackage{calc}
\usepackage[most]{tcolorbox}
\usepackage{matlab-prettifier}
\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
style=Matlab-editor,
basicstyle=\ttfamily\small,
numbersep=22pt,
frame=none
}
\makeatletter
\newlength{\current@boxwidth}
\newtcolorbox{titlebox}[1][]{enhanced,
nobeforeafter,
left skip=0pt,
frame hidden,
boxsep=0pt,
sharp corners,
size=minimal,
#1
}
\newtcblisting{mylisting}[2][]{
arc=0pt, outer arc=0pt,
listing only,
listing style=mystyle,
colbacktitle={gray},
colbacktitle={blue},
code={\setlength{\current@boxwidth}{\widthof{#2}}\colorlet{outercolbacktitle}{tcbcol@backtitle}},% Calculate the box width
title={\begin{titlebox}[width=\current@boxwidth,colupper=tcbcol@title,colback=outercolbacktitle]#2\end{titlebox}},
#1,
}
\makeatother
\begin{document}
\begin{mylisting}[hbox,enhanced,drop shadow, right=3cm]{{\bfseries``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
\end{document}