将行号添加到LaTeX中的自定义阴影环境

问题描述

我想在LaTeX文档中使用自定义阴影环境突出显示一些段落。问题在于这些段落不再获得行号。我该如何解决

以下是示例文档:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{lineno}
\linenumbers
\usepackage{xcolor}
\usepackage{framed}

\newenvironment{myshaded}{\colorlet{shadecolor}{red}\color{green}\begin{shaded}}{\end{shaded}}

\begin{document}

This is a paragraph with line numbers.

\begin{myshaded}
This is a shaded paragraph,but no line numbers.
\end{myshaded}

Another normal paragraph with line numbers.

\end{document}

Image showing pdflatex output

编辑:

在@ samcarter_is_at_topanswers.xyz后面加上注释,添加\begin{internallinenumbers}...\end{internallinenumbers}确实有帮助,但是仍然存在跨多个页面的阴影块的行号错位的问题。在我的设置中,下面的文档无疑将阴影区域的行号放置在阴影区域的最后一页上,这无疑是由于在段落末尾附加了行号lineno package manual states。我没有找到解决办法。

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{lineno}
\linenumbers
\usepackage{xcolor}
\usepackage{framed}

\newenvironment{myshaded}{\colorlet{shadecolor}{red}\color{green}\begin{shaded}\begin{internallinenumbers}}{\end{internallinenumbers}\end{shaded}}

\begin{document}

This is a paragraph with line numbers.

\begin{myshaded}

This is a shaded paragraph,but line numbers misplaced. This is a shaded paragraph,but line numbers misplaced.

\end{myshaded}

Another normal paragraph with line numbers.

\end{document}

Misplaced line numbers

解决方法

您可以使用Container( // background to this Container. decoration: new BoxDecoration( image: new DecorationImage( image: new AssetImage('images/background.png'),fit: BoxFit.cover,),环境为阴影环境激活行号

internallinenumbers

enter image description here