列出前喙和后喙会导致投影仪幻灯片出现错误

列出前喙和后喙会导致投影仪幻灯片出现错误

下列的这个答案,我试图将一个带有长行的列表嵌入到投影仪框架中。

我希望在换行处有一个漂亮的红色箭头(如图所示这里)。

编译时参数prebreakpostbreak出错。事实上,\textcolor出错的是。

以下是改编的 MWE:

\documentclass[xcolor={svgnames,usenames,dvipsnames,table}]{beamer}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{listings}

\lstset{%
    xleftmargin=3.4pt,
    xrightmargin=3.4pt,
    %keepspaces=true,
    columns=fullflexible,   % Rasterize the columns
    frame=single,
    basicstyle=\ttfamily\small,
    inputencoding=utf8,
    extendedchars=\true,
    backgroundcolor=\color{black!10},
    breaklines=true,
% This works
    postbreak=\mbox{$\hookrightarrow$\space},
% This does not work
    postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
}


\begin{document}

\begin{frame}[fragile]{Test}
\begin{lstlisting}
This is a long line. This is a long line. This is a long line. This is a long line. This is a long line.
This is another long line. This is another long line. This is another long line. This is another long line.
\end{lstlisting}
\end{frame}
\end{document}

这是代码的输出,显然没有\textcolor

MWE 输出

如果我取消注释该postbreak行,我会收到此错误:

! Missing number, treated as zero.
<to be read again> 
                   \kern 
l.3 This 
         is a long line. This is a long line. This is a long line. This is a...
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

textcolor关于为什么会导致事情崩溃,有什么想法吗?

答案1

正如已经建议的那样其他 答案,你应该把箭头放在一个盒子里面,这将有助于脆弱的环境:

\documentclass[xcolor={svgnames,usenames,dvipsnames,table}]{beamer}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{listings}

\newsavebox{\mypostbreak}
\savebox{\mypostbreak}{\mbox{\textcolor{red}{$\hookrightarrow$}\space}}
\lstset{%
    xleftmargin=3.4pt,
    xrightmargin=3.4pt,
    %keepspaces=true,
    columns=fullflexible,   % Rasterize the columns
    frame=single,
    basicstyle=\ttfamily\small,
    inputencoding=utf8,
    extendedchars=\true,
    backgroundcolor=\color{black!10},
    breaklines=true,
% This works
    % postbreak=\mbox{$\hookrightarrow$\space},
% This now also works
    postbreak=\usebox{\mypostbreak},
}

\begin{document}

\begin{frame}[fragile]{Test}
\begin{lstlisting}
This is a long line. This is a long line. This is a long line. This is a long line. This is a long line.
This is another long line. This is another long line. This is another long line. This is another long line.
\end{lstlisting}
\end{frame}
\end{document}

在此处输入图片描述

相关内容