0

Question

I want to put a non-float tabular environment inside of a description list after a line break. I want said table to left align with the labels. What value does the description environment use for an indent?

MWE (default behavior)

\documentclass{article}

\usepackage{tabularx}

\begin{document}
  \begin{description}
    \item [$\vert$ line me up]
    ~\\
    \begin{tabular}{ll}
      $\vert$ here & more text \\
      $\vert$ and here & even more text 
    \end{tabular}
    \item [$\vert$ some other item]
  \end{description}
\end{document}

MWE (closer to what I want)

\documentclass{article}

\usepackage{tabularx}

\begin{document}
  \begin{description}
    \item [$\vert$ line me up]
    ~\\
    \begin{minipage}{\linewidth}\hspace{-1.1cm}
    \begin{tabular}{ll}
      $\vert$ here & more text \\
      $\vert$ and here & even more text 
    \end{tabular}
    \end{minipage}
    \item [$\vert$ some other item]
  \end{description}
  
\end{document}

An example of the second MWE shows that the vertical lines are not aligned.

The question restated

In the second example, I would like to replace 1.1cm with whatever internal spacing value my document class uses to indent following a list item. I imagine it would be something like \listindent.

  • Does this variable/constant exist?
  • If not, how can I find the spacing my document class is using?
  • Is there a better or more elegant way to align these things?

What this question is not.

5
  • 1
    not totally related but ~\\ is rather weird input and probably not what is intended. Commented Jul 5, 2022 at 23:29
  • @DavidCarlisle - Good catch, but it is intentional for the hacky MWE. The $\vert$ line me up should be in brackets for the description format. To force a line break after that requires character, hence the forced space.
    – WesH
    Commented Jul 8, 2022 at 14:18
  • No ~\\ is just always wrong, even in a MWE. Just leave a blank line. line me up ~\\ happens to work here but forces two spaces before the line break so if line me up happened to be longer (within two spaces of the right margin) ~\\ would force two line breaks, with one extra line just carring the space tokens. Commented Jul 8, 2022 at 14:26
  • I edited the MWE to show you what I mean. The description item text not in the label is placed immediately following the label, regardless of the natural carriage return line breaks. I need to somehow force a linebreak with \\. Without the ~ the compiler complains that there is no line there to end.
    – WesH
    Commented Jul 8, 2022 at 14:39
  • changing \item xxx to \item[xxx] changes the question rather a lot:-) Never use ~\\ you could use \mbox{}\\ Commented Jul 8, 2022 at 15:03

2 Answers 2

1

Several changes are required. Use the enumitem package. Specify \leftmargin for the indent of the environment, specify itemindent=0pt to left align the table to the left margin, and specify your tabular specification with a leading @{}, so that no tabular margin is applied to the first column.

\documentclass{article}

\usepackage{tabularx,enumitem}

\begin{document}
\noindent Left margin
  \begin{description}[leftmargin=3pt, itemindent=0in]
    \item $\vert$ line me up
    ~\\
    \begin{tabular}{@{}ll}
      $\vert$ here & more text \\
      $\vert$ and here & even more text 
    \end{tabular}
    \item $\vert$ some other item
  \end{description}
\end{document}

enter image description here

A specification of [leftmargin=5pt] seems to adjust the line inputs without adjusting the default description indent.

2
  • From what I read, using the @{} tabular option seems more canonical. However, it seems like an extra step compared to @Bernard's answer. Why would I want to take the extra step to use @{} AND increase the pagemargin by 4pt?
    – WesH
    Commented Jul 5, 2022 at 21:11
  • @WesH The tabular margin can be locally changed either by the user or the document class, and is set by the length \tabcolsep. Its default value in the article class is 6pt, which you can determine via \the\tabcolsep. You need to understand that increasing a pagemargin by a physical value (e.g., +4pt) will likely work only for the particulars of a given document class, or even of a particular user's preference. Commented Jul 5, 2022 at 21:18
1

Is it what you want?

    \documentclass{article}
    \usepackage{enumitem}
    \usepackage{tabularx}

    \begin{document}

      \begin{description}[leftmargin=-1pt, labelindent=0pt]
        \item $\vert$ line me up
        ~\\
        \begin{tabular}{ll}
          $\vert$ here & more text \\
          $\vert$ and here & even more text
        \end{tabular}
        \item $\vert$ some other item
      \end{description}

    \end{document} 

enter image description here

2
  • This is functional. But what was the original labelindent and leftmargin?
    – WesH
    Commented Jul 5, 2022 at 21:12
  • Normally, in a description environment, labelindentis 0pt. I don't lnpw the exact value of leftmargin (probably a fraction of labelwidth) and the value I used was found by trial & error.
    – Bernard
    Commented Jul 5, 2022 at 21:17

You must log in to answer this question.

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