1

In this 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}

I don't know why the left indent in the text part. Any help?

1 Answer 1

3

Beacuse, tcolorbox defines some default options for listings.

enter image description here

In particular, all code is suposed to be LaTeX and tcblatex style is applied. This style is defined in tcblistings.code.tex as

\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}

In this case breaklines is the option which produces the indention after first line. It is defined this way in listings package as you can see in next code:

\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}

First frame uses tcblatex style and second frame uses a regular listings listing with breaklines option. The result is:

enter image description here

The indention is defined with parameter breakindent in listings package, so you can always add

listing options={breaklines, breakindent=0pt}

to your myexample definition and eliminate the indention.

1
  • Ignasi: thanks for a wonderful explication and a perfect solution. May 30, 2016 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.