# How to implement common layouts instead of misusing tabular environments?

Note: My hope is that this can become a general resource for "use a list instead" comments. If you have suggestions for improvement, please let me know.

I often see comments such as

This layout should be typeset using a list, not a tabular.

and (my favorite, paraphrasing because I cannot find the exact quotation right now)

If every tabularx with an lX preamble was a list instead, the world would be a better place.

This is all well and good, and I can see the benefits (chiefly: page breaking mid-"row" and without specialty table packages).

A description environment gets close, but it has a fixed left indent that does not depend on the longest item name.

The accepted answer at Automatically set description list labelwidth based on widest label? shows a way to do this using the environ and enumitem packages.

What other methods do you use to achieve this layout? I'd like to avoid manually specifying the longest label (its width, essentially). This is something that tabularx does not require, and I don't want it to be required in the solution to this problem either, if I can avoid it.

Alternatively, what other layouts are recommended for this type of content? Examples of common document elements for which tabularx is used include nomenclature lists and other lists of notation.

MWE

\documentclass{article}
\usepackage{tabularx}
\usepackage{lipsum} % just for blind texts
\newenvironment{mylist} % what else goes here?
{\trivlist}
{\endtrivlist}

\begin{document}

\section{trivlist version}
\begin{mylist}
\item[Text 2] \lipsum*[2]
\end{mylist}

\section{tabularx version}
\noindent
\begin{tabularx}{\textwidth}{@{}lX@{}}
Text 2 & \lipsum*[2]
\end{tabularx}

\section{description version}
\begin{description}
\item[Text 2] \lipsum*[2]
\end{description}

\end{document}


• Are you looking for something like labeling from KOMA-script scrextend)? Please see also Make the lines of a description item line up Mar 9 '15 at 20:18
• @Johannes_B that gives the layout that I want, but it requires separate entry of the longest label, something that tabularx does not require and that I wish to avoid. Mar 9 '15 at 20:23
• Gonzalo Medina's answer here tex.stackexchange.com/questions/230537/… Mar 9 '15 at 20:44
• Is it perhaps something like this what you need? tex.stackexchange.com/a/130099/3954 Mar 9 '15 at 21:15
• @GonzaloMedina yes, that's basically it. Sorry I did not find the solution in my searching. Mar 9 '15 at 21:20

It's hard to give a general answer, but below are some table questions that I've answered with a list (not all of which were accepted by the OP:-) It's usually possible to use a custom list layout that gives a very rigid tabular-like appearance, but with just technical advantages like easier page breaking, but sometimes having decided not to use a table, you end up deciding to use a more fluid layout using more standard list (or section heading) layout.

The comment about a longest label is a case in point. To measure the longest label you either need a multiple pass solution, either multiple runs of latex (like longtable) or multiple trials within the same run (like tabularx) both of which are relatively easy these days (the environ package makes it easy to do tabularx-like trial runs) but if you convince yourself that a more heading-like layout is appropriate, the issue magically goes away as the indentation of the text isn't controlled by the length of the label.

Tables with very long texts

Lots of text in one table cell

Longtable with two column

Best practices longtable

Longtable with items

parameter description with long descriptions and long lists -- possibility of page break?

• Thanks for answering (+1). I'll take a look at your previous answers. I think I'm at the mercy of the community now to decide the fate of my more-ill-posed-than-expected question. :-) Mar 9 '15 at 23:43

i have a love-hate relationship with all lists and tabulars. none of them really does what i want for a situation like the one described, which is exactly what one wants for, say, a list of notation.

here's a simple approach that does require one to figure out which entry "label" is the longest, but it breaks nicely across pages because each entry is a paragraph, and if one does get a really long "label", it can always be packed up as a \parbox to be top-aligned.

\documentclass{article}

\newlength\mylistindent
\noindent \hangindent\mylistindent
\makebox[\mylistindent]{\hfill #1\enspace}\ignorespaces
}

\begin{document}
\thispagestyle{empty}
\settowidth\mylistindent{the longest\kern.5em}

\mylist{First} this is the text for the first item.
\mylist{Second} this is the text for the second item.  It is
very long, and may require several lines.
\mylist{Another} one more here
\mylist{the longest} this one has both a long label and a
long text.  it keeps going on, and on, and on, and on,
and on, \ldots
\mylist{Final} one more to finish off.

\medskip
\noindent
You'll need to put in some explicit space at the end.

\end{document}


you want the entries left-aligned? just shift the \hfill to the beginning.

you want more (or less) space between entries? just modify the \addvspace.

the kind of data that usually gets included in notation lists almost begs for \raggedright (or its counterpart from ragged2e), so don't count out that possibility.

• it's possible to add a "check for longest" routine into this method, write the result to the .aux file, and read it in on the next run. as pointed out by david carlisle, this does require (at least) two runs of latex. if the question is reopened, i'll try to add one. Mar 10 '15 at 13:31