1

I've been fiddling around with a table and was wondering if someone could help me improve this:

\documentclass{report} 
\usepackage{array}
\begin{document}
\begin{tabular}[]{p{2em}  p{4in}} 
xy     &     Some text, some more text \\
yz     &     Some other text, some more text \\
\multicolumn{2}{>{\hangindent=2em}p{3in}}{this is longer \quad Some other text, some more and more and more text, a lot of text} \\
zz     &     Some further text, some more text \\
\end{tabular}
\end{document}

A two-column table where the left column is very small but where some rows might contain information that I'd like to go over into the second column. And the hangindent of the second column should still align with the column. Furthermore, I'd want to specify the width of the second column to use the entire rest of the textwidth. Maybe a table is the wrong approach. Any suggestions welcome.

enter image description here

1 Answer 1

1

You can use tabularx to produce a fit-to-width type table.

enter image description here

\documentclass{article}

\usepackage{tabularx}
\usepackage[nopar]{lipsum}

\begin{document}

\noindent
\begin{tabularx}{\linewidth}{ @{} p{2em} X @{} } 
  xy & Some text, some more text \\
  yz & Some other text, some more text \\
     & \hspace{\dimexpr-2em-2\tabcolsep}this is longer \quad Some other text, \lipsum[2] \\
  zz & Some further text, some more text
\end{tabularx}

\end{document}

Instead of using \multicolumn with a \hangindent, just move the first line over to the left with a negative space on the first line. The column gaps on the other edges have been removed using a @{} column specifier.


A tabular-like construction will not break across the page boundary mid-paragraph (or row). If this is a concern, you can use a list like a description. enumitem provides some easy functionality for this using the style=sameline:

enter image description here

\documentclass{article}

\usepackage{enumitem}
\usepackage[nopar]{lipsum}

\begin{document}

\begin{description}[font=\normalfont, leftmargin=2.5em, style=sameline, noitemsep]
  \item[xy] Some text, some more text
  \item[yz] Some other text, some more text
  \item[this is longer\quad] Some other text, \lipsum[2]
  \item[zz] Some further text, some more text
\end{description}

\end{document}

I've emphasized the gap between the item and the subsequent text by inserting a \quad.

2
  • 1
    Might it have been easier to accomplish this with a description environment?
    – jan
    Dec 3, 2016 at 6:45
  • @jan: Sure. I've added an example using enumitem's style = sameline.
    – Werner
    Dec 3, 2016 at 6:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .