在 itemize 环境中,列表文本超出框的范围

在 itemize 环境中,列表文本超出框的范围

我试图在枚举环境中列出列表,但是文本超出了框的范围,如下所示:

在此处输入图片描述

您能告诉我如何调整文本或加宽框架以使文本正确显示吗?

以下是代码:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Pascal
}

\newtcblisting{mylisting}[2][]{
    arc=0pt, outer arc=0pt,
    listing only,
    listing style=mystyle,
    title=#2,
    #1
    }

\begin{document}

\begin{enumerate}
\item This is an example
\noindent
\begin{mylisting}[hbox,enhanced,drop shadow,width=6in]{\bfseries{vpasolve for $\mathbf{f(y)}$}}
syms y
vpasolve((1.2*y)*(1-(y/15)) - (4*y)/(0.5+y) == 0, y)
\end{mylisting}
\end{enumerate}

\end{document}

答案1

这是带换行符的版本。它必须使用自己的样式,因为您可能不想减小所有列表的行宽(tcolorboxes 除外)。

清单

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Pascal,
}

\lstdefinestyle{mytcbstyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Pascal,
breaklines=true,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}},
linewidth=.8\linewidth
}

\newtcblisting{mylisting}[2][]{
    arc=0pt, outer arc=0pt,
    listing only,
    listing style=mytcbstyle,
    title=#2,
    #1
    }

\begin{document}

\begin{enumerate}
\item This is an example
\noindent
\begin{mylisting}[hbox,enhanced,drop shadow,width=6in]{\bfseries{vpasolve for $\mathbf{f(y)}$}}
syms y
vpasolve((1.2*y)*(1-(y/15)) - (4*y)/(0.5+y) == 0, y)
\end{mylisting}
\end{enumerate}

\end{document}

答案2

加载enumitem并使用该wide选项enumerate似乎可以解决问题:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{showframe, enumitem}
\renewcommand\ShowFrameLinethickness{0.3pt}
\tcbuselibrary{listings,skins}

\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Pascal
}

\newtcblisting{mylisting}[2][]{
    arc=0pt, outer arc=0pt,
    listing only,
    listing style=mystyle,
    title=#2,
    #1
    }

\begin{document}

\begin{enumerate}[wide]
\item This is an example
\begin{mylisting}[hbox,enhanced,drop shadow]{\bfseries{vpasolve for $\mathbf{f(y)}$}}
syms y
vpasolve((1.2*y)*(1-(y/15)) - (4*y)/(0.5+y) == 0, y)
\end{mylisting}
\end{enumerate}

\end{document} 

在此处输入图片描述

相关内容