Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In continuation of this question, I tried to make a list of items each consisting of unbreakable text. This can be done manually using minipage:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum} %for example
\setlength{\textheight}{7cm} %about one item fits per page
\begin{document}
\begin{itemize}
\item\begin{minipage}[t]{\linewidth}
\lipsum[1]
\end{minipage}
\item\begin{minipage}[t]{\linewidth}
\lipsum[2]
\end{minipage}
\end{itemize}
\end{document}

What I would like it to to define a list environment that is just like itemize (or whatever) only that the items are automatically inserted into a minipage as in my manual example. The solution should be robust for nested list environments, so if \item is to be redifined, it has to be done so in a very gentle way...not sure how. After redefining the environment itemize-block (for example) the following code should compile and not break the text in each item across pages:

\begin{itemize-block}
\item
\lipsum[1]
\item \begin{itemize}
\item let us make sure it compiles even with 
\item a nested list...
\end{itemize}
\item
\lipsum[2]
\end{itemize-block}

This can surely be done...only I have no idea how.

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

This is how I would do it:

\newenvironment{block-itemize}{%
  \itemize
  \let\olditem\item
  \let\closepage\relax  
  \renewcommand\item[1][]{%
    \closepage\olditem[#1]\minipage[t]{\linewidth}%
    \let\closepage\endminipage
  }%
}{%
  \closepage
  \enditemize
}

Then you write

\begin{block-itemize}
\item \lipsum[1]
\item \lipsum[2]
\end{block-itemize}

And a short explanation: When it starts, the environment begins a regular \itemize and then saves the usual definition of \item into \olditem. Then \item is redefined so that: (1) it closes the “previous” minipage (2) it starts a regular item (using \olditem) and (3) it opens a new minipage. Of course, for the very first item there is no minipage to close, that's why \closepage is first defined as \relax (do nothing) but it is then redefined to \endminipage right after the first use of \item. The end of the environment simply closes both the last minipage and the itemize environment.

Note: Actually, I would use something like \my@olditem and \my@closepage and throw the whole definition into a style file so that I don't accidentally redefine commands from another package. But I wanted to keep the code above somewhat clean without all those @'s lying around.

share|improve this answer
    
Thanks! Nice solution. I had to adapt it a little since the minipages inhibit the inter-item spacing. But that wasn't very difficult, using an additional \def. –  Yossi Farjoun Oct 24 '10 at 11:14
    
Sorry, I had to remove the checkmark since I was having trouble with your solution. The problem with redefining \item the way you do it is that it affects any nested list and causes errors when there are nested lists. I edited my Question to reflect this usecase. –  Yossi Farjoun Oct 24 '10 at 14:46
3  
As a cheap solution, how about defining a new \Item (or something) instead of messing with the existing \item? –  Juan A. Navarro Oct 24 '10 at 14:52
    
What should one do in order have the same trick but for 'description' item? Simple reusing this code cleans term formatting of description list items (outputs as [term], instead of boldify) –  glaz666 Feb 1 '12 at 10:27
    
@glaz666, I edited the code to take this into account. It's not a particularly elegant solution, and I haven't tested it, but I guess you could give it a try. –  Juan A. Navarro Feb 13 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.