如何防止“leftbar”破坏“marinpar”?

如何防止“leftbar”破坏“marinpar”?

我正在使用\leftbar包提供的命令框架突出显示边距注释。不幸的是,一旦在嵌套枚举环境中插入注释,leftbar 似乎会以某种方式破坏边距宽度的计算。我在下面提供了一些最小的工作示例代码来说明这个问题。在枚举环境中使用时,有没有什么方法可以使其正常工作\marginpar\leftbar

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{framed}

\begin{document}
\lipsum[1]
\marginpar
{
    \begin{leftbar}
    \vspace{0.5em}
        This is a comment next to regular text.
    \end{leftbar}
}
\lipsum[2-3]
\begin{enumerate}
    \item First item.
    \item Second item.
    \item Third item.
    \begin{description}
        \item[First] is the first sub item of the third item.
        \item[Second] is the second sub item of the third item.
    % !!! At this point things go horribly wrong.
            \marginpar
            {
                \begin{leftbar}
                \vspace{0.5em}
                    This is a comment inside a nested description, the width of the margin is somehow off.
                \end{leftbar}
            }
        \item[Third] is the third sub item of the third item.
    \end{description}
\end{enumerate}
\lipsum[4-5]
\marginpar
{
    \begin{leftbar}
    \vspace{0.5em}
        Once we're back in regular text the margin width is calculated properly again.
    \end{leftbar}
}
\lipsum[5]
\end{document}

答案1

我不知道您是否认为这是一个有效的答案,因为它并没有真正解决问题……但是使用包mdframed而不是framed,您可以规避这个问题。在包文件的注释中,framed指出该包可能仅在将来的版本中支持 marginpars。

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{mdframed}    % instead of \usepackage{framed} 

\newmdenv[leftmargin=0pt,innertopmargin=0pt,innerbottommargin=0pt,innerrightmargin=0pt,innerleftmargin=10pt,hidealllines=true,leftline=true,linewidth=3pt]{leftbar}
                         % this creates a similar leftbar environment 

\begin{document}
\lipsum[1]
\marginpar
{
    \begin{leftbar}
    \vspace{0.5em}
        This is a comment next to regular text.
    \end{leftbar}
}
\lipsum[2-3]
\begin{enumerate}
    \item First item.
    \item Second item.
    \item Third item.
    \begin{description}
        \item[First] is the first sub item of the third item.
        \item[Second] is the second sub item of the third item.
            \marginpar
            {
                \begin{leftbar}
                \vspace{0.5em}
                    This is a comment inside a nested description, the width of the margin is somehow off.
                \end{leftbar}
            }
        \item[Third] is the third sub item of the third item.
    \end{description}
\end{enumerate}
\lipsum[4-5]
\marginpar
{
    \begin{leftbar}
    \vspace{0.5em}
        Once we're back in regular text the margin width is calculated properly again.
    \end{leftbar}
}
\lipsum[5]
\end{document}

相关内容