在此 MWE 中
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\newtcblisting{myexample}{
width=1.01\linewidth, sharp corners,%
beforeafter skip=0.5\baselineskip,%
sidebyside gap=2mm,%
lower separated=false,middle=0pt,%
colframe=red, enhanced, %
interior style={top color=yellow!5!white,bottom color=yellow!5!white},%
righthand width=3cm,halign=left,%
listing side text,%
after=,%
}
\begin{document}
\begin{frame}[fragile]{Sample tcolorbox code}{A simple tcolorbox code}
\begin{myexample}
I don't know why the next text is left indent after the second line.
\end{myexample}
\end{frame}
\end{document}
我不知道为什么文本部分有左缩进。有什么帮助吗?
答案1
因为,tcolorbox
为 定义了一些默认选项listings
。
具体来说,所有代码都应该应用LaTeX
某种tcblatex
风格。这种风格定义tcblistings.code.tex
为
\lstdefinestyle{tcblatex}{language={[LaTeX]TeX},
aboveskip={0\p@ \@plus 6\p@}, belowskip={0\p@ \@plus 6\p@},
columns=fullflexible, keepspaces=true,
breaklines=true, breakatwhitespace=true,
basicstyle=\ttfamily\small, extendedchars=true, nolol,
inputencoding=\kvtcb@listingencoding}
在这种情况下,breaklines
选项会在第一行后产生缩进。它在listings
包中是这样定义的,如下面的代码所示:
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\newtcblisting{myexample}{
width=1.01\linewidth, sharp corners,%
beforeafter skip=0.5\baselineskip,%
sidebyside gap=2mm,%
lower separated=false,middle=0pt,%
colframe=red, enhanced, %
interior style={top color=yellow!5!white,bottom color=yellow!5!white},%
righthand width=3cm,halign=left,%
listing side text,%
after=,%
}
\begin{document}
\begin{frame}[fragile]{Sample tcolorbox code}{A simple tcolorbox code}
\begin{myexample}
I don't know why the next text is left indent after the second line.
\end{myexample}
\end{frame}
\begin{frame}[fragile]
\begin{lstlisting}[breaklines=true]
I don't know why the next text is left indent after the second line.
\end{lstlisting}
\end{frame}
\end{document}
第一帧使用tcblatex
样式,第二帧使用带选项listings
的常规列表breaklines
。结果是:
breakindent
缩进是在包中使用参数定义的listings
,因此您可以随时添加
listing options={breaklines, breakindent=0pt}
按照您的myexample
定义并消除缩进。