tcblisting 代码中的左缩进

tcblisting 代码中的左缩进

在此 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定义并消除缩进。

相关内容