将类更改为 beamer 不会指定颜色虚线!如何修复该问题?

将类更改为 beamer 不会指定颜色虚线!如何修复该问题?

在此回答

将课程改为投影机没有指定虚线颜色!如何修复该问题?

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[ruled,vlined]{algorithm2e}

\definecolor{algoColorKeyword}{named}{blue}
\definecolor{algoColorComment}{named}{olive}

\renewcommand{\KwSty}[1]{{\color{algoColorKeyword}\textbf{#1}}}
\renewcommand{\CommentSty}[1]{{\color{algoColorComment}\texttt{#1}}}

\makeatletter

\def\algocf@Hlne{%
  \hbox{\leaders \hbox{\vrule width 3pt height 0.6pt depth 0pt \hskip 2pt } \hskip 10pt}}


\def\mydashbox#1#2{%
\setbox0\hbox{#2}%
\dimen0\ht0
\advance\dimen0\dp0
\setbox2\vbox to \dimen0{{\color{#1}\leaders\vbox{\vskip2pt\hrule height 3pt width .6pt}\vfill}}%
\ht2=\ht0
\dp2=\dp0
\box2
\unhbox0
}

% The following lines come from algorithm2e.sty
%
% Block with a vertical line end by a little horizontal line
        \renewcommand{\algocf@Vline}[1]{%
                \strut\par\nointerlineskip%t
                \algocf@push{\skiprule}%
                \hbox{%
%                        {\color{algoColorKeyword}\vrule}% HERE !
\mydashbox{algoColorKeyword}{%
                        \vtop{%
                                \algocf@push{\skiptext}%
                                \vtop{\algocf@addskiptotal\advance\hsize by -\skiplength #1}%
                                {\color{algoColorKeyword}\Hlne}% HERE !
                        }%
}
                }\vskip\skiphlne%
                \algocf@pop{\skiprule}%
                \nointerlineskip%
        }

% The following lines come from algorithm2e.sty
%
% Block with a vertical line
        \renewcommand{\algocf@Vsline}[1]{%
                \strut\par\nointerlineskip%
                \algocf@push{\skiprule}%
                \hbox{%
%                        {\color{algoColorKeyword}\vrule}% HERE !
\mydashbox{algoColorKeyword}{%
                        \vtop{\algocf@push{\skiptext}%
                        \vtop{\algocf@addskiptotal\advance\hsize by -\skiplength #1}}%
                }%
}
                \algocf@pop{\skiprule}%
        }
\makeatother

\begin{document}
\scriptsize

\begin{algorithm}[H]
        \tcp{Un exemple d'algorithme haut en couleur...}
        \BlankLine
        \KwData{Données au départ}
        \KwResult{Ce que fait cet algorithme}
        \BlankLine
        \While{La boucle doit continuer}{
                \eIf{Condition 1}{
                        \tcp{Un tout premier test...}
                        Action 1 \\
                        Action 2
                }{
                        \For{$i = 2$ \KwTo $l$}{
                                Calcul $i$ \\
                                Action $i$
                        }
                        \tcp{
                                Un autre test \\
                                plus compliqué...
                        }
                        \uIf{Condition 2}{
                                Action $l + 1$ \\
                                Action $l + 2$
                        }
                        \ElseIf{Condition 3}{
                                Action $l + 3$ \\
                                Action $l + 4$
                        }
                }
        }

        \caption{Un exemple d'algorithme}
\end{algorithm}

\end{document}

输出:TL2019TL2018 如果\usepackage[ruled,vlined]{algorithm2e}

在此处输入图片描述

编辑:输出Texlive 2015 与 XeLatex 如果\usepackage[ruled,vlined]{algorithm2e} 在此处输入图片描述

输出:如果使用 Xelatex,则使用 TL2015

\usepackage[ruled]{algorithm2e}

在此处输入图片描述

但是在TL2015中使用PdfLatex,输出就像TL2019一样。

答案1

将命令更改\mydashbox

\def\mydashbox#1#2{%
  \setbox0\hbox{#2}%
  \dimen0\ht0
  \advance\dimen0\dp0
                          % delete \color{#1} in next line
  \setbox2\vbox to \dimen0{\leaders\vbox{\vskip2pt\hrule height 3pt width .6pt}\vfill}%
  \ht2=\ht0
  \dp2=\dp0
  % add \textcolor in next line
  \textcolor{#1}{\box2}%
  \unhbox0
}

解决了您的问题。目前我还不知道“为什么”这个问题。

相关内容