3

How can I get multiple left-margin bars using the mdframed package? I can get a single left bar using, e.g.

\documentclass{article}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}[linewidth=1,topline=false,rightline=false,bottomline=false]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed orci quis urna volutpat tincidunt. Praesent ultrices commodo auctor. Nunc vel nulla sed arcu aliquet faucibus quis nec ante. Nam elementum neque vitae sem fringilla a euismod eros malesuada. Duis orci eros, tincidunt et venenatis at, tristique in tortor
\end{mdframed}
\end{document}

with output

enter image description here

The motivation for this question is to format email correspondence in LaTeX. So if an email cites a previous email that cites a previous email, two left bars will be needed.. To achieve this one could try to nest the mdframed environments to get something like

enter image description here

The problem with the latter is that mdframed environment does not allow page breaks for nested environments. It means that it will break down if the cited text takes up more than a page. If the enivronment is not nested, it allows page breaks though..

More specifically, for the general case, I would like to have an environment say myframe taking an integer argument that specifies the number of left bars to use. Such that I could write, for instance

\documentclass{article}
\usepackage{mdframed,lipsum}
\begin{document}
\def\numbars{3}
\begin{myframe}{\numbars}
  \lipsum[1-10]
\end{myframe}
\end{document}
  • 1
    The issue with nested frames is nearly insolvable with the current implementation. The current implementation means that nested environments are nested vbox. Your second issue can be solved. – Marco Daniel May 24 '13 at 8:07
  • @MarcoDaniel I am very impressed by the package..:) It seems that there are many ways to modify the behavior of the boundaries of the frames..so maybe this can be used to produce the desired effect instead? – Håkon Hægland May 24 '13 at 8:16
  • Which framemthod do you want to use? Most users are using framemethod=tikz. Related to your method, the modification must be done. – Marco Daniel May 24 '13 at 8:28
  • I am not sure.. I have used the default so far.. Is there any differences in behavior? – Håkon Hægland May 24 '13 at 8:35
  • The behaviour isn't different (I hope) but the implementation differs. If you want to use tikz you have more possibilities. – Marco Daniel May 24 '13 at 8:58
5

The following solution can be used as a starting point.

Let me start with some new keys.

The example defines some new keys for mdframed:

  1. quotelinewidth -- Set the line width of the quote line
  2. quoteleveldistance -- Set the distance between quoted lines if more than 1 quote levels are used
  3. quotelevel -- Set the level of the quotation

Coincident the tikzstyle quoteline is defined which specifies the style of quoteline. Default the color of the key middlelinecolor is used.

Here the example whereby page breaks are working as usual.

enter image description here

\documentclass{article}
%\usepackage{showframe}
\usepackage[framemethod=tikz]{mdframed}%load xparse

\makeatletter
\mdf@dolist{\mdf@do@lengthoption}{%
   {quotelinewidth==1pt},%
   {quoteleveldistance==5pt},%
}
\newcounter{quotelevel}
\define@key{mdf}{quotelevel}[1]{%
  \setcounter{quotelevel}{#1}%
}%

\tikzset{quoteline/.style={}}%

\tikzset{quoteline/.append style={%
  draw=\mdf@middlelinecolor,%
  line width=\mdf@quotelinewidth@length%
}}%



\newcommand\computequotelines{%
 \wlog{MDF-INFO: quotelevel \the\value{quotelevel}}%
 \ifcase\value{quotelevel}%level 0
      \mdfsetup{hidealllines=true}%
 \or%level 1
     \wlog{quotelinewidth=\the\mdf@quotelinewidth@length and quoteleveldistance=\the\mdf@quoteleveldistance@length}%
     \setlength{\mdf@middlelinewidth@length}{\mdf@quotelinewidth@length}%
     \mdfsetup{innerleftmargin=\mdf@quoteleveldistance@length}%
 \else%more than 1 level
     \wlog{quotelinewidth=\the\mdf@quotelinewidth@length and quoteleveldistance=\the\mdf@quoteleveldistance@length}%
      \setlength{\mdf@middlelinewidth@length}{%
          \dimexpr \value{quotelevel}\mdf@quotelinewidth@length
            + \numexpr\value{quotelevel}-1\relax\mdf@quoteleveldistance@length
        }%
     \mdfsetup{innerleftmargin=\mdf@quoteleveldistance@length}%
 \fi
 \renewrobustcmd*\mdf@tikzbox@otl[2]{%one or two borders
    \clip(0,0)rectangle(\mdfboundingboxwidth,\mdfboundingboxheight);%
    \foreach \x in {1,...,\value{quotelevel}} {%
       \path[transform canvas={%
             xshift=   (\x-1)*\mdf@quoteleveldistance@length
                          -0.5\mdf@middlelinewidth@length
                          +0.5\mdf@quotelinewidth@length,},
         quoteline,mdfcorners,]##1;%
    }
 }%
}
\makeatother
\mdfdefinestyle{quotestyle}{%
    middlelinecolor=blue,quotelinewidth=2pt,
    hidealllines=true,leftline=true,%only leftline
    skipabove=11pt,skipbelow=11pt,
    innerleftmargin=0pt,innerrightmargin=0pt,
    settings=\computequotelines,}
\newmdenv[style=quotestyle]{myframe}
\usepackage{lipsum}
\begin{document}

\begin{myframe}[quotelevel=1]
  \lipsum[3]
\end{myframe}

\begin{myframe}[quotelevel=2]
  \lipsum[2]
\end{myframe}

\begin{myframe}[quotelevel=3]
  \lipsum[1]
\end{myframe}
\end{document}
| improve this answer | |
  • Seems to be just what I was looking for.. :-) Thank you very much Marco! – Håkon Hægland May 24 '13 at 10:20
  • 1
    @HåkonHægland: Of course you can expand the code to get different colors for different levels. – Marco Daniel May 24 '13 at 10:34

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.