tcolorbox 中的逐字文本超出右边距

tcolorbox 中的逐字文本超出右边距
\documentclass{article}
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[sidebyside=true, title=test]
\begin{verbatim}
this is <strong>not</strong> a test this is not a test this is not a test

$x+2=0$
$x=-2$
$x$ is negative
\end{verbatim}
\tcblower
Right part.
\end{tcolorbox}

\end{document}

在此处输入图片描述

错误是“Overfull \hbox too wide”。我正在阅读 tcolorbox 文档,但我不明白为什么会发生这种情况。

左边部分的文字要保留在里面,怎么做?

编辑

也许解决方案是使用 lstlisting 和 breaklines=true 而不是 verbatim。

答案1

姆韦

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\begin{tcblisting}{sidebyside,title=Test}

% Example of LaTeX code

This is \textbf{not} a test. This is not a test. This is not a test. This is not a test.  

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\end{tcblisting}
\end{document}

如果右侧的内容与使用 LaTeX 编译的列出的代码的输出有某种不同:

mwe2

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\begin{tcblisting}{sidebyside,title=Test, listing and comment, 
comment={

% Example of LaTeX code

This is \textbf{not} a test. (...)

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\bigskip 

\ttfamily\color{magenta} This is (more or less) the result
}}

% Example of HTML + LaTeX code

This is <strong>not</strong> a test. This is not a test. This is not a test. This is not a test.  

$x+2=0$

$x=-2$ \dotfill $x$ is negative

\end{tcblisting}
\end{document}

相关内容