2

I'm using the \leftbarcommand provided by the package framed to highlight margin notes. Unfortunately leftbar seems to somehow break the calculation of the margin width once a comment is inserted inside a nested enumeration environment. I've provided some minimal working example code below to illustrate the issue. Is there any way to make \marginpar and \leftbar work together properly when used inside enumeration environments?

\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

I don’t know if you consider this a valid answer, since it does not really solve the problem … but using the package mdframed instead of framed, you can circumvent this problem. In the comments of the framed package file it is stated that the package may support marginpars only in future versions.

\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}
  • I did some testing based on your suggested workaround. It seems to work properly where \leftbar from the framed package fails. While your solution comes with the burden of having to define your own leftbar, said definition is easy to understand and very compact. IMO This makes your solution a viable answer to my question. Thank you very much for sharing this . – norritt Feb 2 '18 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.