algorithm2e 中的行号超出了范围

algorithm2e 中的行号超出了范围

这是我的代码:

\documentclass[11pt]{llncs}
\usepackage[utf8]{inputenc}
\usepackage{parskip}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{float}
\usepackage{multicol}
\usepackage{fixltx2e}
\usepackage{multicol}
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
  }

\usepackage[T1]{fontenc}
\usepackage{comment} 
\usepackage{amsmath}                                    % 
\setcounter{MaxMatrixCols}{20}
\usepackage[margin=1in]{geometry}
\usepackage[noend, boxruled, linesnumbered]{algorithm2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{hyperref}
\definecolor{bl}{rgb}{0.0,0.2,0.6} 
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\usepackage{sectsty}
\hypersetup{
    colorlinks, linkcolor={dark-red},
    citecolor={dark-blue}, urlcolor={medium-blue}
}
\usepackage{graphicx}
\usepackage[compact]{titlesec} 
\newtheorem{observation}{\textsc{Observation}}
%%% Start of the document
\begin{document}
\begin{algorithm}[H]
\label{alg:seed}
    \SetAlgoLined
     \SetKwInOut{Input}{input}
    \Input{\textsc{Graph} $G$}
    line number outside the box\;
    another line\;
    a third line\;
    what is going on?\;
    \caption{\textsc{Caption}}
\end{algorithm}
\end{document}

输出如下: 在此处输入图片描述

哪个命令将行号发送到框外?

答案1

如果您先加载,则可以在同一个文档中使用algorithm2e和:parskipalgorithm2e

\usepackage[noend, boxruled, linesnumbered] {algorithm2e}
\usepackage{parskip}

在此处输入图片描述

代码:

\documentclass[11pt]{llncs}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{float}
\usepackage{multicol}
\usepackage{fixltx2e}
\usepackage{multicol}
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
  }

\usepackage[T1]{fontenc}
\usepackage{comment} 
\usepackage{amsmath}
\setcounter{MaxMatrixCols}{20}
\usepackage[margin=1in]{geometry}
%
\usepackage[noend, boxruled, linesnumbered] {algorithm2e}
\usepackage{parskip}
%
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{hyperref}
\definecolor{bl}{rgb}{0.0,0.2,0.6} 
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\usepackage{sectsty}
\hypersetup{colorlinks, linkcolor={dark-red},
citecolor={dark-blue}, urlcolor={medium-blue}}
\usepackage{graphicx}
\usepackage[compact]{titlesec} 
\newtheorem{observation}{\textsc{Observation}}

\usepackage{blindtext}% dummy text
% Start of the document
\begin{document}
\begin{algorithm}[H]
\label{alg:seed}
    \SetAlgoLined
    \SetKwInOut{Input}{input}
    \Input{\textsc{Graph} $G$}
    line number outside the box\;
    another line\;
    a third line\;
    what is going on?\;
    \caption{\textsc{Caption}}
    return
\end{algorithm}
\blindtext

\blindtext
\end{document}

答案2

我不知道是什么原因导致了冲突,我的研究表明,删除parkskip包会将行号发送到框中。

在此处输入图片描述

\documentclass[11pt]{llncs}
\usepackage[utf8]{inputenc}
%\usepackage{parskip}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{float}
\usepackage{multicol}
\usepackage{fixltx2e}
\usepackage{multicol}
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
  }

\usepackage[T1]{fontenc}
\usepackage{comment} 
\usepackage{amsmath}                                    % 
\setcounter{MaxMatrixCols}{20}
\usepackage[margin=1in]{geometry}
\usepackage[noend, boxruled, linesnumbered] {algorithm2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{hyperref}
\definecolor{bl}{rgb}{0.0,0.2,0.6} 
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\usepackage{sectsty}
\hypersetup{colorlinks, linkcolor={dark-red},
citecolor={dark-blue}, urlcolor={medium-blue}}
\usepackage{graphicx}
\usepackage[compact]{titlesec} 
\newtheorem{observation}{\textsc{Observation}}
%%% Start of the document
\begin{document}
\begin{algorithm}[H]
\label{alg:seed}
    \SetAlgoLined
    \SetKwInOut{Input}{input}
    \Input{\textsc{Graph} $G$}
    line number outside the box\;
    another line\;
    a third line\;
    what is going on?\;
    \caption{\textsc{Caption}}
    return
\end{algorithm}
\end{document}

相关内容