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.

I often use an eqnarray (I know it's better to use align, but let's not worry about that for this question unless it changes the answer) as a way to list a bunch of definitions or descriptions of symbols. Here's an example:

\begin{eqnarray*}
  f & \text{:} & \begin{minipage}[t]{\textwidth}The objective function that we're trying to maximize.\end{minipage} \\
  h & \text{:} & \begin{minipage}[t]{\textwidth}The concave heuristic function that we can use to approximate $f$.\end{minipage}
\end{eqnarray*}

This produces: enter image description here

A common problem, however, is that if my descriptions are too long, they will bleed past the end of the page. I've discovered that minipage can help in these kinds of situations. I've tried something like this:

    \begin{eqnarray*}
      \sqrt{\sin{f-g}} & \text{:} & \begin{minipage}[t]{\textwidth}This is the description of a function but unfortunately goes past the right margin over the edge of the page.\end{minipage}
    \end{eqnarray*}

However, this causes the content to bleed over past the right margin, as seen:

enter image description here

One hack to fix this is to manually figure out how 'long' this minipage block should be, and use that measurement instead of \textwidth in the above code block. This is inflexible and requires change whenever the lenght of my equations change. How do I use a box/environment/other solution to automatically begin a newline when the text hits the absolute right margin on the page? My desired output would look something like:

enter image description here

Thank you!

share|improve this question
2  
A tabularx environment would work wonders here. Are you at all concerned with breaking such an environment across the page boundary? –  Werner Oct 30 '13 at 17:12
4  
There is no possibility of f & \text{:} & \begin{minipage}[t]{\textwidth} fitting into \textwidth as the third column is already that wide, so it is overfull even if empty. You should use a list, eg \begin{description}\item[$\sqrt{\sin f-g}$: ] This is.... –  David Carlisle Oct 30 '13 at 17:14
    
Thanks for the tip, Werner! tabularx seems promising, however it seems to have the same problem: imgur.com/UhqQMBv. The code that produced that is below. (Sorry, I don't know how to put code blocks in comments!) Suggestions? \begin{tabularx}{\textwidth}{rcl} $f$ &:& The objective... \\ $h$ &:& The heuristic... \\ $\sqrt{\sin{f-g}}$ &:& This is the description of a function but unfortunately goes past the right margin over the edge of the page. \end{tabularx} –  Michael Tingley Oct 30 '13 at 17:54
    
Using \begin{tabularx}{\textwidth}{rcX}...\end{tabularx} seems to have accomplished what I was looking for, thanks! –  Michael Tingley Oct 30 '13 at 18:01

1 Answer 1

up vote 4 down vote accepted

The following option uses tabularx to set the list/descriptions, and is therefore not breakable across the page boundary:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\newenvironment{mylist}
  {\par\centering\vspace{\abovedisplayskip}%
   \tabularx{\linewidth}{@{}l@{~:~}X@{}}}
  {\endtabularx
   \par\vspace{\belowdisplayskip}}
\begin{document}
\lipsum[2]

\begin{mylist}
  $f$ & The objective function that we're trying to maximize. \\
  $h$ & The concave heuristic function that we can use to approximate~$f$\kern-.2em. \\
  $g$ & \lipsum*[2]
\end{mylist}

\lipsum[2]

\begin{mylist}
  $f$ & The objective function that we're trying to maximize. \\
  $h$ & The concave heuristic function that we can use to approximate~$f$\kern-.2em.
\end{mylist}

\lipsum[2]
\end{document}

You have to use an X-column in order to benefit from tabularx's automatic resizing of columns. I've also used \linewidth instead of \textwidth, since the former is more appropriate if you're inside other list-like environments (where \textwidth might be too wide). As reference, see Difference between \textwidth, \linewidth and \hsize.

For ease-of-use, I've only used two columns, with the middle-column always being a colon (~:~). It just promotes consistency to have a general setup, rather than duplicating the output for no apparent reason.

Note that your mylist environment will always have width \linewidth, even though the descriptions might be very short.

share|improve this answer
    
This is fantastic, thank you very much! One last question, it seems that putting a tabularx environment inside of a center environment doesn't center the list/descriptions. How would you recommend accomplishing this? (Of course, this is only relevant if the width of the longest row on the table is less than the linewidth.) –  Michael Tingley Oct 30 '13 at 20:24
    
@MichaelTingley: Yes, in those instances, if you wish to have things centered, a different approach would have to be taken (possibly a 2-stage process: measure first, then set). tabularx requires a length according to which it measures and sets the X-columns. So, even if your contents is not as wide as \linewidth, it will be made to fit \linewidth. One could manage the two-stage process, but I'll have to do that later... –  Werner Oct 30 '13 at 20:40

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.