8

i've been requested to indent the first paragraph in an environment defined with mdframed.

i've looked at the question Paragraph indenting in an mdframed environment, and while it provides a workaround, there really has to be a more subtle way of doing this. (i can't find any indication in the manual that this facility is provided; an option like [indentfirst = true] would be really nice.)

here's the test file:

\documentclass[11pt]{amsbook}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{etoolbox}

% define (using mdframed) a highlighted block with a double line on the
% left along the (inside) edge of the text block.
%
\mdfdefinestyle{twolined}{%
   leftline=true,rightline=false,topline=false,bottomline=false,%
   outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
   outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
   innerleftmargin=6pt,innerrightmargin=0pt,%
   innertopmargin=0pt,innerbottommargin=0pt,%
%   splittopskip=0pt,splitbottomskip=0pt.%
   skipabove=.5\baselineskip,skipbelow=.5\baselineskip
}
\newmdenv[%
   leftline=true,rightline=false,topline=false,bottomline=false,%
   outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
   outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
   innerleftmargin=6pt,innerrightmargin=0pt,%
   innertopmargin=0pt,innerbottommargin=0pt,%
%   splittopskip=0pt,splitbottomskip=0pt.%
%   skipabove=.5\baselineskip,skipbelow=.5\baselineskip%
   skipabove=1\baselineskip,skipbelow=.5\baselineskip%
]{linedintro}

% patch the command on which linedintro is based, to try to restore the
% paragraph indentation on the first line.
%
\makeatletter
\patchcmd\mdf@lrbox
   {\parindent\z@}{\parindent\normalparindent\relax}{}{}
\makeatother

\begin{document}
\thispagestyle{empty}

\noindent Some unindented random text.

\begin{linedintro}
First paragraph within the lined environment.
Add some text to make it two lines long.

Second paragraph within the lined environment.  Make it two lines long.
\end{linedintro}

\noindent Some more unindented random text.
\end{document}

output:

output of example code

i've tried resetting other instances of \parindent, but to no effect. (i may just be looking in the wrong place, but it's not obvious what is the right place.)

if i rename the environment in the definition to xlinedintro and add a "derivative" environment

\newenvironment{linedintro}{%
  \begin{xlinedintro}
  \parindent\normalparindent
  \hspace*{\normalparindent}\ignorespaces
 }{%
  \end{xlinedintro}%
}

this will force the indent on the first paragraph. but the real situation is quite a bit more complicated, and sometimes there is something else (a marginnote) that must come between the beginning of the environment and the actual text, so it's necessary to be careful with the input to avoid extra unwanted space.

is there a better place to apply a patch? or some other way to accomplish the indentation with more subtlety?

1 Answer 1

7

I can offer a patch for linedintro that in turn patches \mdf@lrbox and \mdf@trivlist (locally) for adding the required indentations.

\documentclass[11pt]{amsbook}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{etoolbox}

% define (using mdframed) a highlighted block with a double line on the
% left along the (inside) edge of the text block.
%
\mdfdefinestyle{twolined}{%
   leftline=true,rightline=false,topline=false,bottomline=false,%
   outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
   outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
   innerleftmargin=6pt,innerrightmargin=0pt,%
   innertopmargin=0pt,innerbottommargin=0pt,%
%   splittopskip=0pt,splitbottomskip=0pt.%
   skipabove=.5\baselineskip,skipbelow=.5\baselineskip
}
\newmdenv[%
   leftline=true,rightline=false,topline=false,bottomline=false,%
   outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
   outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
   innerleftmargin=6pt,innerrightmargin=0pt,%
   innertopmargin=0pt,innerbottommargin=0pt,%
%   splittopskip=0pt,splitbottomskip=0pt.%
%   skipabove=.5\baselineskip,skipbelow=.5\baselineskip%
   skipabove=1\baselineskip,skipbelow=.5\baselineskip%
]{linedintro}

% patch the command on which linedintro is based, to try to restore the
% paragraph indentation on the first line.
%
\makeatletter
\newcommand{\indentforlinedintro}{%
  \patchcmd\mdf@lrbox{\parindent\z@}{\parindent\normalparindent\relax}{}{}%
  \patchcmd\mdf@trivlist{\itemindent\z@}{\itemindent\normalparindent}{}{}%
}
\patchcmd{\linedintro}{\begin}{\indentforlinedintro\begin}{}{}
\makeatother

\begin{document}
\thispagestyle{empty}

Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.

\begin{linedintro}
First paragraph within the lined environment.
Add some text to make it two lines long.

Second paragraph within the lined environment.  Make it two lines long.
\end{linedintro}

\noindent Some more unindented random text.
\end{document}

enter image description here

A key indent= might be very useful indeed.

1
  • 2
    beautiful! i wouldn't have thought of patching the environment just defined; clearly i need more practice with patching. thank you. and i'll submit a request to the author of mdframed for an indent key. Oct 16, 2014 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .