I want to recreate the text boxes shown in the figure below. This is from the book Doctor Lawd's labyrinth The box starts in the page while extending till the margin.
How can this be achieved? In MWE below I have used the solution suggested here using mdframed. I have added and adjusted the leftmargin and rightmargin with trial and error to achieve a similar/workable result. But I would like to add the lengths so that solution is generic using textwidth and marginpar. Another issue in this approach is that there is blank space above and below the box. Can this space be utilised in wrapping the regular text above/below the box (I have tried setting skipabove=0pt but has not effect on that).
Also finally this solution works for article class but if you set the documentclass to book the boxes are inside the main textwidth and don't extend till the marginpar. And for even pages I would like the boxes on the left-hand side of the page (as seen in the first page layout from the old book), not on the right-hand side (which is correct for odd pages).
MWE
\documentclass{article}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{wrapfig}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\newenvironment{WrapText}[1][r]
{\wrapfigure{#1}{0.3\textwidth}\mdframed[backgroundcolor=gray!20,
hidealllines=true,leftmargin=0,
rightmargin=-0.25\textwidth,skipabove=0pt,skipbelow=0pt]}
{\endmdframed\endwrapfigure}
\begin{document}
\lipsum[1]
\marginpar{This is some margin par}
\begin{WrapText}
The quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog.
\end{WrapText}
\lipsum[1]
\clearpage
\newpage
\lipsum[2]
\marginpar{This is some margin par}
%\hspace{4cm} % this doesnt work
\begin{WrapText}
The quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog.
\end{WrapText}
\lipsum
\end{document}




vspace. See the edited answer. – jlab Mar 30 '24 at 10:58