13

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}
hwhm
  • 559
  • This question is similar to: http://tex.stackexchange.com/questions/52023/mdframed-put-something-on-the-start-of-one-vertical-left-rule Does it help? – Marco Daniel May 29 '12 at 11:54
  • @MarcoDaniel I am not an expert in tiKZ or mdframed but indeed I tried modifying that code and without success. The problem with (my use of) the method described in your link is that the position of the line depends on the object you put next to it. – hwhm May 29 '12 at 12:24
  • Does the (i) represent anything? – Marco Daniel May 29 '12 at 15:46
  • @MarcoDaniel I have resolved it by myself actually... Add something like firstextra={\node[text width=3em,align=right,outer sep=0em,inner sep=0em] at ($(P-|O)+(-1.5em,-10pt)$) {(i)\;\;\;};} and also for singleextra etc. – hwhm May 29 '12 at 16:44
  • If it works ;-). – Marco Daniel May 29 '12 at 17:07
  • If you found a solution, you may post it as an answer to your own question so that this question can be marked as answered an my help other people too. – Tobi May 29 '12 at 20:20

1 Answers1

9

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.

hwhm
  • 559
  • 1
    Nice. Note that \quad can be used in text mode too so you can omit the $’s around it. – Tobi May 29 '12 at 22:38
  • @Tobi I did realise that one but somehow it didn't work unless I put the dollar signs in... – hwhm May 29 '12 at 23:37
  • 1
    Thats strange, I guess it has to do with the node … But why don’t you use left alignment, like \node[text width=2em,fill=red,align=left,outer sep=0em,inner sep=0em] at ($(P-|O)+(-1em,-9pt)$) {(i)};? – Tobi May 30 '12 at 07:26
  • @Tobi I actually intended to use right alignment. I guess it's just a matter of taste. In my example in the question, you can imagine if (i) is left-aligned a lot of space will be left to the right of (i). If you then try and place (i) about half-way in between, when you get to (iii) it will look a bit cramped. – hwhm May 30 '12 at 11:29
  • @hwhm: Do you want to use it as king of enumerate? Why do you use -1em.-0.9em? Working with such length are a little bit dangerous. – Marco Daniel May 30 '12 at 19:11
  • You edit is wrong. It doesn't depend on the font. – Marco Daniel May 31 '12 at 19:45
  • @MarcoDaniel My eyes are playing tricks on me. It does depend on the magnification at which you look at the outcome, but I changed the adjustment to 0.5pt anyway, which sort of works for both Computer Modern and Times. You should have kept your answer! – hwhm May 31 '12 at 19:59
  • 1
    @hwhm: Again -- It doesn't depends on the font. It depends on the height of the first line. A simple way would be to add a \rule{0pt}{\ht\strutbox} to become the same height. Then The node can be set with \strut\smash{(i)}. – Marco Daniel May 31 '12 at 20:00
  • @MarcoDaniel Would you mind editing my answer? – hwhm May 31 '12 at 20:03
  • @hwhm: There are an other mistake too -- you compute - 0.5*(0,\the\mdflength{middlelinewidth}) whereby no top line is drawn. – Marco Daniel May 31 '12 at 20:23
  • @MarcoDaniel Yes I was lazy and just copied your code... – hwhm May 31 '12 at 20:26