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:
\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.
If I understand correctly this is more or less what you had in mind:
Basically what did was add the following:
frametitle={\ifodd\value{page} \rlap{\hspace*{15pt} Example} \else \llap{Example \hspace*{15pt}}\fi},, %This is used to overright the numbering rightafter the "Example" in the original frame title (which was above the text)
frametitlealignment={\ifodd\value{page} \raggedleft \else \raggedright\fi},
- The word "Example" is not directly above the title as before, it's
now beside.
- There is no numbering on it.
- The word "Example" does change from left/right on
odd/even pages.
- The word "Example" gets correctly positioned even
when the mdframed spread across pagebreak.
Note how the example
environment still uses the frametitle with numbering above the text, unlike the style=example
.
Additional tuning might be required to change text color/font or box it, etc.
Full code:
\documentclass[12pt,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc, positioning, shapes.geometric}
\tikzset{
node distance= 0mm and 3mm,
ws/.style={align=#1,
font=\large\bfseries\sffamily,
draw, thin, fill=white,
overlay,
}
}
\makeatletter
\mdfdefinestyle{example}%
{%
hidealllines=true,
skipabove=2\baselineskip, skipbelow=-1ex,
innertopmargin=0pt, innerbottommargin=0pt,%
middlelinewidth=5pt, linecolor=red,%
fontcolor=teal, font=\small\sffamily,%
frametitle={\ifodd\value{page} \rlap{\hspace*{15pt} Example} \else \llap{Example \hspace*{15pt}}\fi},, %This is used to overright the numbering rightafter the "Example" in the original frame title (which was above the text)
frametitlealignment={\ifodd\value{page} \raggedleft \else \raggedright\fi},
%
%
settings={%\global\refstepcounter{example}
\ifodd\value{page}
\boolfalse{mdf@leftline}
\booltrue{mdf@rightline}
\else
\booltrue{mdf@leftline}
\boolfalse{mdf@rightline}
\fi},
innerrightmargin=\ifodd\value{page}0.5em\else 0.0em\fi, %rightmargin=7em,%
innerleftmargin =\ifodd\value{page}0.0em\else 0.5em\fi, %leftmargin =7em,%
singleextra={
% \ifodd\value{page}
%\node[ws=left,below right=of P] {Example}; %These were the numbers beside them
% \else
%\node[ws=right,below left=of O |- P] {Example};
% \fi
},%
}% end of mdfdefinestyle
\makeatother
\mdtheorem[style=example,
]{example}{Example}[chapter]
\mdtheorem[style=exercise,
]{exercise}{Exercise}[chapter]
\begin{document}
\chapter{test}
\begin{mdframed}[style=example]
This is produced by \verb+\begin{mdframed}[style=example] ... \end{mdframed}+
\end{mdframed}
xxxxxxxxx
\begin{example}
This is produced by \verb+\begin{example} ... \end{example}+
\end{example}
\newpage
\lipsum[2]
\begin{mdframed}[style=example]
\lipsum[2]
\end{mdframed}
\begin{mdframed}[style=example]
\lipsum[2]
\lipsum[2]
\lipsum[2]
\lipsum[2]
\end{mdframed}
\end{document}
Edit: After some details added I modified the code to meet:
- Numbering after word "example"
- Left/right according to even/odd page.
- A "continue" text when the frame splits over another page.
To do that I used the firstextra
(add "Exemple numbering" to all frames) and the secondextra
(add "continue" only to first part of splited frames). Read more at secion 7 Hooks and Bools
of mdframed
manual.
And if you wish to add a "continued from" in the last part of the splited frame check this question.
\documentclass[12pt,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc, positioning, shapes.geometric}
\tikzset{
node distance= 0mm and 3mm,
ws/.style={align=#1,
font=\large\bfseries\sffamily,
draw, thin, fill=white,
overlay,
}
}
%\newcounter{example} maybe this is unnecessary
\makeatletter
\mdfdefinestyle{example}%
{%
hidealllines=true,
skipabove=2\baselineskip, skipbelow=-1ex,
innertopmargin=0pt, innerbottommargin=0pt,%
middlelinewidth=5pt, linecolor=red,%
fontcolor=teal, font=\small\sffamily,%
%
settings={\global\refstepcounter{example} %this was commented, it is now active
\ifodd\value{page}
\boolfalse{mdf@leftline}
\booltrue{mdf@rightline}
\else
\booltrue{mdf@leftline}
\boolfalse{mdf@rightline}
\fi},
innerrightmargin=\ifodd\value{page}0.5em\else 0.0em\fi, %rightmargin=7em,%
innerleftmargin =\ifodd\value{page}0.0em\else 0.5em\fi, %leftmargin =7em,%
%
singleextra={
\ifodd\value{page}
\node[ws=left,draw=none,below right=of P] { Example \theexample };
\else
\node[ws=right,draw=none,below left=of O |- P] {Example \theexample };
\fi
},%
firstextra={
\ifodd\value{page}
\node[ws=left,draw=none,below right=of P] { Example \theexample };
\node[ws=left,yshift=-2em,below right=of P] { continue \ldots };
\else
\node[ws=right,draw=none,below left=of O |- P] {Example \theexample };
\node[ws=right,draw=none,yshift=-2em,below left=of O |- P] {continue \ldots };
\fi
},%
}% end of mdfdefinestyle
\makeatother
\mdtheorem[style=example,
]{example}{Example}[chapter]
\mdtheorem[style=exercise,
]{exercise}{Exercise}[chapter]
\begin{document}
\chapter{test}
\begin{mdframed}[style=example]
This is produced by \verb+\begin{mdframed}[style=example] \end{mdframed}+
\end{mdframed}
xxxxxxxxx
\begin{mdframed}[style=example]
This is produced by \verb+\begin{mdframed}[style=example] \end{mdframed}+
\end{mdframed}
\newpage
\lipsum[2]
\begin{mdframed}[style=example]
\lipsum[2]
\end{mdframed}
\begin{mdframed}[style=example]
\lipsum[2]
\lipsum[2]
\lipsum[2]
\lipsum[2]
\end{mdframed}
\end{document}
Best Answer
After clarifications from the OP through comments, it is better to use
\captionof
fromcaption
package and get rid of bothfigure
andtable
environments. For table notes, an extra row may be added as shown.