[Tex/LaTex] mdframed with label outside of box

mdframed

I am looking to do two boxes with mdframed similarly to the following:

enter image description here

The first box is easy but I don't know how to place a label to the left of the second box. The positions of the dashed lines are to be fixed: in particular, the position of the second line should NOT depend on the length of the label "(i)". How should I go about doing this?

I tried using \llap but the label gets cropped.

MWE for the first box:

\documentclass{article}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\mdfdefinestyle{testframe}{topline=false,rightline=false,bottomline=false,%
innerleftmargin=1em,linecolor=white,%
tikzsetting={draw=black,line width=.5pt,dashed,dash pattern= on 1pt off 3pt} }

\begin{document}

\begin{mdframed}[style=testframe]
\lipsum[3]
\end{mdframed}

\end{document}

Best Answer

Update on 31st May: Modified solution based on Marco Daniel's. Incorporated his positioning of the label, and have also included a fixed text width for the label, the "right margin" and the "skip below".


My own solution is to add to the style definition of 'testframe' as follows:

enter image description here

\documentclass{article}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usetikzlibrary{calc}
\newcommand{\mdfLABEL}[1]{\node[text width=2em,align=right,anchor=north east,%
               outer sep=0pt,inner sep=0pt] at ($ (O|-P)
                    -(\the\mdflength{innerleftmargin},0)
                    -0.5*(\the\mdflength{middlelinewidth},0)
                   - (0,\the\mdflength{innertopmargin})
                   + (0,0.5pt)
                 $) {#1};}

\mdfdefinestyle{testframe}{topline=false,rightline=false,bottomline=false,%
    innerleftmargin=1em,linecolor=white,rightmargin=2em,skipbelow=1em,%
    tikzsetting={draw=black,line width=.5pt,dashed,dash pattern= on 1pt off 3pt},%
    firstextra={\mdfLABEL{(i)}},%
    singleextra={\mdfLABEL{(i)}},%
    secondextra={\mdfLABEL{$\phantom{.}$}},%
    middleextra={\mdfLABEL{$\phantom{.}$}},%
}

\begin{document}

\begin{mdframed}[style=testframe]
\lipsum[3]
\end{mdframed}

\end{document}

Note that tikz library calc has been loaded to calculate the label's coordinates. Also, a manual adjustment of +(0,0.5pt) has been made.

Related Question