0

I would like to apply the mdframed environment to a custom list environment which is described here, modified slightly and shown below.

I would like to put a frame (breakable) around each call of the category environment. The requirement for a frame is simply because I am trying to emulate the style of an electronically fillable form.

Please see the following MWE and supporting files:

\documentclass{article}
\usepackage[]{geometry}
\usepackage{lipsum}
%\usepackage{mdframed}

\input{required_code.tex}

\newenvironment{category}[1]{%
    \begin{list}{}{%
    \parsep\parskip%
    \setlength{\itemsep}{-\parsep}%
    }\item {\bfseries \section{#1}
    }%
    \nobreakitem%
    }%
    {\end{list}}%
\begin{document}

\begin{category}{First Category}
\lipsum[1-4]
\end{category}

\begin{category}{Second Category}
\lipsum[5-10]
\end{category}

\end{document}

and required_code.tex looks like:

\makeatletter
% copied from ltlists.dtx
\def\nobreakitem{%
  \@inmatherr\nobreakitem
  \@ifnextchar [\@nobreakitem{\@noitemargtrue \@nobreakitem[\@itemlabel]}}
\def\@nobreakitem[#1]{%
  \if@noparitem
    \@donoparitem
  \else
    \if@inlabel
      \indent \par
    \fi
    \ifhmode
      \unskip\unskip \par
    \fi
    \if@newlist
      \if@nobreak
        \@nbitem
      \else
        \addpenalty\@beginparpenalty
        \addvspace\@topsep
        \addvspace{-\parskip}%
      \fi
    \else
      \addpenalty\@M%only new bit!
      \addvspace\itemsep
    \fi
    \global\@inlabeltrue
  \fi
  \everypar{%
    \@minipagefalse
    \global\@newlistfalse
    \if@inlabel
      \global\@inlabelfalse
      {\setbox\z@\lastbox
       \ifvoid\z@
         \kern-\itemindent
       \fi}%
      \box\@labels
      \penalty\z@
    \fi
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}%
  \if@noitemarg
    \@noitemargfalse
    \if@nmbrlist
      \refstepcounter\@listctr
    \fi
  \fi
  \sbox\@tempboxa{\makelabel{#1}}%
  \global\setbox\@labels\hbox{%
    \unhbox\@labels
    \hskip \itemindent
    \hskip -\labelwidth 
    \hskip -\labelsep
    \ifdim \wd\@tempboxa >\labelwidth
      \box\@tempboxa
    \else
      \hbox to\labelwidth {\unhbox\@tempboxa}%
    \fi
    \hskip \labelsep}%
  \ignorespaces}
\makeatother
2
  • I don't see what this code does that simple sections cannot do.
    – Bernard
    Commented Feb 12, 2017 at 19:10
  • @Bernard, you're right, probably too complex. The complexity comes from wanting to frame refsections with a box. I will study this example: tex.stackexchange.com/questions/131742/…
    – John Chris
    Commented Apr 18, 2017 at 20:13

0

You must log in to answer this question.

Browse other questions tagged .