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 am trying to write a document with a list of paragraphs that have an introductory caption displayed to the left of the first line of each paragraph, such that the captions appear as a left column and the paragraphs as a right column. All this appears within a standard one-column article.

What I have come up with is to use a table. I have:

\begin{tabularx}{\linewidth}{l X}
First row caption & \lipsum[1]\\
Second row caption & \lipsum[2]\\
Third row caption & \lipsum[3]\\
Fourth row caption & \lipsum[4]
\end{tabularx}

If the lipsum in that example is replaced with real paragraph text, it becomes quite unwieldy due to the fact it's all embedded together and the need for line continuations it is all rather messy. What I'd like is something like this:

\begin{captioned-text}{First row caption}
\lipsum[1]}
\end{captioned-text}
\begin{captioned-text}{Second row caption}
\lipsum[2]}
\end{captioned-text}
\begin{captioned-text}{Third row caption}
\lipsum[3]}
\end{captioned-text}
\begin{captioned-text}{Fourth row caption}
\lipsum[4]}
\end{captioned-text}

With real text in place (potentially multiple paragraphs of real text) this would be more readable.

I am hoping that there is some package out there that does this kind of thing already and I have just not found it. Is there a better way to achieve this than using a table ?

share|improve this question
1  
can't you just put your caption in \marginpar ? –  David Carlisle Apr 11 '13 at 14:36
    
I want the caption inside the margin. If you imagine the normal textwidth then the caption and body would appear as two columns, the widths being decided by the longest caption. I'll take a look at parbox/minipage. –  starfry Apr 11 '13 at 15:00
    
Oh in that case you want a list –  David Carlisle Apr 11 '13 at 15:20
    
@StevenB.Segletes why would you use a parbox or minipage inside an X column (which is already a parbox) ? –  David Carlisle Apr 11 '13 at 15:22
    
I think this is essentially a duplicate of the following which shows settings as both lists or tables: tex.stackexchange.com/questions/89995/… –  David Carlisle Apr 11 '13 at 15:24

3 Answers 3

up vote 2 down vote accepted

Well, thanks to Piotr Wydrych, I stumbled onto mdwlist and it does just what I want:

\usepackage{mdwlist}
\begin{basedescript}{\desclabelwidth{4cm}}
    \item[First caption] \lipsum[1]
    \lipsum[2]
    \item[Second caption] \lipsum[3]
    \item[Third caption] \lipsum[4]
 \end{basedescript}
share|improve this answer

Generally, tables should be used to compare a number of facts, not to typeset lists of paragraphs. Have you looked at the description environment? It works well with more than one paragraph per caption.

\begin{description}
\item[First caption] \lipsum[1]

\lipsum[2]

\item[Second caption] \lipsum[3]
\item[Third caption] \lipsum[4]
\end{description}
share|improve this answer
    
Tables just give horizontal and vertical alignment for a closed part of the main text body. They are not connected to semantics. The only rule about tables is, that you should use it, if you want that horizontal and vertical alignment (for example in order to emphasize two-dimensional connections). –  Toscho Apr 11 '13 at 16:54

The following is not perfect (spacing between captioned-text blocks, fixed-width left column/caption width and page-breaking within blocks), but provides the interface you're after:

enter image description here

\documentclass{article}
\usepackage{environ,lipsum}% http://ctan.org/pkg/{environ,lipsum}
\NewEnviron{captioned-text}[2][0.3\linewidth]{%
  \noindent%
    \begin{tabular}{@{}p{#1}p{\dimexpr\linewidth-#1-2\tabcolsep}@{}}
      #2 & \BODY
    \end{tabular}
}
\begin{document}
\begin{captioned-text}{First row caption}
\lipsum[1]
\end{captioned-text}
\begin{captioned-text}{Second row caption}
\lipsum[2]
\end{captioned-text}
\begin{captioned-text}{Third row caption}
\lipsum[3]
\end{captioned-text}
\begin{captioned-text}{Fourth row caption}
\lipsum[4]
\end{captioned-text}
\end{document}

The environ package provides the interface, capturing the entire contents of captioned-text, and placing it into a fixed-width column tabular. The left-hand column has default width of 0.3\linewidth, while the right-hand column takes up the remainder of the space.

Page-breaking within the paragraph text would require a completely different approach (see next). However, the space between blocks could be adjusted to suit your needs.


parcolumns can also be used to circumvent the caveat of the previous approach and lack of page-breaking capability:

\usepackage{environ,lipsum,parcolumns}% http://ctan.org/pkg/{environ,lipsum,parcolumns}
\NewEnviron{captioned-text}[2][0.3\linewidth]{%
  \begin{parcolumns}[colwidths={1=#1,2=\dimexpr\linewidth-#1-2em},nofirstindent]{2}
    \colchunk[1]{#2}%
    \colchunk[2]{\BODY}%
  \end{parcolumns}
}
share|improve this answer
    
why did you not use longtable? –  stalking is prohibited Apr 11 '13 at 15:30
    
@Karl'sstudents: longtable would allow breaking across pages, but not within cells, so there is no use for it in the first implementation. –  Werner Apr 11 '13 at 15:37

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.