Text FormattingItemized List in Case Differentiation

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Itemized List in Case Differentiation

Post by MatthiasN »

Hello everyone,

I was wondering if there is a way to put a cases environment around an itemize environment. What I've tried:

Code: Select all

\documentclass{report}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}
$\begin{cases}
\text{
\begin{itemize}
\item This is item 1.
\item This is item 2.
\item And so on.
\end{itemize}
}
\end{cases}$
\end{document}
Obviously this doesn't work, otherwise I wouldn't be posing this question. Is there a way to make this work?

Kind regards,
Matthias

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Itemized List in Case Differentiation

Post by cgnieder »

You'd need to put a box around {itemize}:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[
\begin{cases}
 \text{%
 \parbox{.7\linewidth}{%
 \begin{itemize}
  \item foo
  \item bar
  \item baz
 \end{itemize}
 }}
\end{cases}
\]

\end{document}
Regards
site moderator & package author
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Itemized List in Case Differentiation

Post by MatthiasN »

Thanks cgnieder, it works!

I did encounter another problem though. What I really want to use are right cases with rcases. I asked about the cases environment, because I figured it would be the same. It does work with rcases, but it leaves a very large horizontal space between the text and the cases. Do you know if there is any way to solve this?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Itemized List in Case Differentiation

Post by cgnieder »

You might have noticed that \parbox's first argument takes a dimension (i.e. a length that TeX can interpret) as argument that specifies the width of the box. In the example I posted I set it to 70% of the current line width. You can choose a smaller value:

Code: Select all

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\[
\begin{rcases}
 \text{%
 \parbox{50pt}{%
 \begin{itemize}
  \item foo
  \item bar
  \item baz
 \end{itemize}
 }}
\end{rcases}
\]

\end{document}
Regards
site moderator & package author
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Itemized List in Case Differentiation

Post by MatthiasN »

Oh, OK. I am not really familiar with \parbox. If you don't mind explaining, why does it work with the \parbox, but not without. And what is the purpose of \parboxes?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Itemized List in Case Differentiation

Post by cgnieder »

Ok, I'll try to explain as far as I understand it (*). To know what boxes are in a TeX context and how it places them you need to know about TeX's modes. There are six different modes Tex and hence LaTeX can be in when parsing a document. I'll only explain four of them: 1) horizontal mode 2) vertical mode 3) math mode and 4) display math mode.

When TeX sees the beginning of a paragraph it goes into horizontal mode. There every character is interpreted in a box and all these boxes are glued together into a long line, the horizontal list, until the end of the paragraph is reached. Tex now tries different scenarios of breaking this horizontal list into several lines that build the paragraph. Once it has done so TeX goes into vertical mode and the paragraph is set as a large box on the vertical list, i.e. a long list of paragraphs.

Since TeX doesn't know anything about letters but only sees boxes of different height, depth and width a box can in principle contain anything, e.g. a tabular, say.

Math mode is similar to horizontal mode but characters are seen as different boxes and spacing is different (there are other differences, really, but my knowledge is not deep enough to explain them). Again the boxes are glued together and after leaving math mode the resulting boxes are placed on the horizontal list.

Display math mode is again similar but the resulting list is placed on the vertical list.

amsmath's \text macro temporarily leaves math mode and goes into horizontal mode (not quite true again, I believe). The {itemize} environment internally starts a new paragraph which means it goes into vertical mode first. As this is impossible in math mode we need to give LaTeX a chance to do so by putting it into an appropriate (that is vertical) box which is done by \parbox here.

I hope this at least made some sense...

You can find an overview over LaTeX's box macros here: What are the different kinds of boxes in (La)TeX?

Regards

(*) I hope someone will correct me where I am wrong.
site moderator & package author
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Re: Itemized List in Case Differentiation

Post by MatthiasN »

Thanks a million! I believe I understood it. Thanks for your time.
Post Reply