在枚举环境中使用时“修复”列表环境

在枚举环境中使用时“修复”列表环境

在下面给出的代码中,我的列表环境在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} 

在此处输入图片描述

相关内容