![在枚举环境中使用时“修复”列表环境](https://linux22.com/image/362477/%E5%9C%A8%E6%9E%9A%E4%B8%BE%E7%8E%AF%E5%A2%83%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%97%B6%E2%80%9C%E4%BF%AE%E5%A4%8D%E2%80%9D%E5%88%97%E8%A1%A8%E7%8E%AF%E5%A2%83.png)
在下面给出的代码中,我的列表环境在enumerate
环境中出现偏差:
如何修复代码,使enumerate
环境内的列表框看起来像环境外的列表框enumerate
?谢谢!
以下是代码:
\documentclass{article}
\usepackage{calc}
\usepackage[most]{tcolorbox}
\usepackage{matlab-prettifier}
\usepackage{enumitem}
\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={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}
This is how the \texttt{mylisting} box appears outside of the \texttt{enumerate} environment:
\begin{mylisting}[hbox,enhanced,drop shadow,right = 2cm]{\bfseries{``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
This is how the \texttt{mylisting} box appears inside of the \texttt{enumerate} environment:
\begin{enumerate}[label=\alph*)]
\item
\begin{mylisting}[hbox,enhanced,drop shadow,right = 2cm]{\bfseries{``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
\item This is just some random text
\end{enumerate}
\end{document}
答案1
它与附加迷你页面一起工作
\documentclass{article}
\usepackage{calc}
\usepackage[most]{tcolorbox}
\usepackage{matlab-prettifier}
\usepackage{enumitem}
\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={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}
This is how the \texttt{mylisting} box appears outside of the \texttt{enumerate} environment:
\begin{mylisting}[hbox,enhanced,drop shadow,right = 2cm]{\bfseries{``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
This is how the \texttt{mylisting} box appears inside of the \texttt{enumerate} environment:
\begin{enumerate}[label=\alph*)]
\item
\begin{minipage}[t]{\dimexpr\linewidth-\leftmargin}
\vspace{-\baselineskip}
\begin{mylisting}[hbox,enhanced,drop shadow,right = 2cm]{\bfseries{``cubemaster'' Usage}}
cubemaster(13);
\end{mylisting}
\end{minipage}
\item This is just some random text
\end{enumerate}
\end{document}