How do I draw a line on the INNER margin in a double-sided document?

With the mdframed package one can draw nice lines on the left or right of the text. For example:

\documentclass[a4paper,twoside,11pt]{article}

\usepackage[framemethod=TikZ]{mdframed}

\mdfdefinestyle{MDFStyGrayBar}{%
linecolor=gray,
backgroundcolor=white,
%
outerlinewidth=5pt,
%
topline=false,
bottomline=false,
rightline=false,
leftline=true,
%
innertopmargin=4pt, %\baselineskip
innerbottommargin=8pt,
innerrightmargin=3pt,
innerleftmargin=3pt,
%
skipabove=\topskip,
skipbelow=\topskip
}

\begin{document}

\noindent Some normal text.
\begin{mdframed}[style=MDFStyGrayBar]
Some text with a vertical bar on the left.
\end{mdframed}

\end{document}


looks like this:

But what if I want the line to be on the inner side in a double-sided ("twoside") document? That is, on the left for a right-page and on the right for a left-page? This should also work, when the frame extends over several pages. Is that possible with the mdframed package?

• Does this answer do anything like what you want? (Note: it relies on geometry.)
– jon
Jun 27, 2013 at 16:42
• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Jun 27, 2013 at 16:53
• @jon: I can't see any relations to your linked question. Jun 27, 2013 at 16:53
• @MarcoDaniel -- I don't follow; are you suggesting I delete the comment? The answer is surely related to some degree: it draws a line on the margins. And I implied (at least) that it doesn't use your package. I didn't post it as an answer because it clearly doesn't answer the question vis-à-vis the specific reference to mdframed. But cross-linking answers in comments seems to me to increase the utility of TeX.SX in general because future readers may decide the linked-to answers were actually the one(s) they were looking for. (It's not like I was voting to close or anything....)
– jon
Jun 27, 2013 at 17:16
• @MarcoDaniel -- Great! That hack does the job! Thank you!
– John
Jun 28, 2013 at 8:28

mdframed detects whether it is used inside twoside mode. If it's true you can adjust length by innermargin and outermargin. The hack below adds some options to the original definition. If you are on an odd page the setting \mdfsetup{hidealllines=true,leftline=true} is used. On the other hand \mdfsetup{hidealllines=true,rightline=true} is used.

\documentclass[a4paper,twoside,11pt]{article}

\usepackage[framemethod=TikZ]{mdframed}
\makeatletter
\newrobustcmd*\if@mdf@pageodd@bar{%
\zref@refused{mdf@pagelabel-\the\value{mdf@zref@counter}}%
\ifodd\zref@extract{mdf@pagelabel-\the\value{mdf@zref@counter}}%
{mdf@pagevalue}%
\setlength\mdf@rightmargin@length{\mdf@outermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@innermargin@length}%
\mdfsetup{hidealllines=true,leftline=true}%
\else
\setlength\mdf@rightmargin@length{\mdf@innermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@outermargin@length}%
\mdfsetup{hidealllines=true,rightline=true}%
\fi%
}
\newrobustcmd*\changepageodd{\let\if@mdf@pageodd\if@mdf@pageodd@bar}
\makeatother
\mdfdefinestyle{MDFStyGrayBar}{%
linecolor=gray,
backgroundcolor=white,
%
outerlinewidth=5pt,
%
topline=false,
bottomline=false,
rightline=false,
leftline=true,
%
innertopmargin=4pt, %\baselineskip
innerbottommargin=8pt,
innerrightmargin=3pt,
innerleftmargin=3pt,
%
skipabove=\topskip,
skipbelow=\topskip,
settings={\changepageodd}
}
\usepackage{showframe,lipsum}
\begin{document}

\noindent Some normal text.
\begin{mdframed}[style=MDFStyGrayBar]
\lipsum
\end{mdframed}

\end{document}