5

I am trying to emulate a table with nested enumerate lists. From my reading, using a table is impossible - lets assume that is true. I am generating the latex from javascript.

What I am trying to do is: line up the first item on the right with the TOP LINE of the corresponding item on the left

This is what I currently have: enter image description here

and here is what I want: enter image description here

This is the latex that I am using (to generate just one "row"):

\documentclass[14pt, letterpaper]{article} 
\usepackage{fancyhdr} 
\usepackage[head=41.68335pt]{geometry} 
\usepackage{enumitem} 
\usepackage{indentfirst} 


\begin{document} 
    \pagebreak\textbf{Part One - General}
    \begin{enumerate}
    [leftmargin=*,topsep=0pt,itemsep=0pt,label={1.\arabic*}]
    \begin{tabular}{p{0.3\textwidth}}

        \item\flushleft\textbf{SECTION INCLUDES}

    \end{tabular}
    \begin{enumerate}
        [align=left, leftmargin=180pt, labelwidth=30pt,label={.\arabic*}]
        \item Work covered by Contract documents 
        \item Contract Method 

    \end{enumerate}
    \end{enumerate}
\end{document}

I know how to shift up the lines by a certain amount (\vspace{20pt} will move it up a single line), but I need to move it up by \vspace{20pt} * lines_in_header

Anyone have any insights on how to do this?

edit minipage/table overflow ugliness: (as you can see, I set the \textheight=5cm...look for the page number) enter image description here

  • 2
    Tabulars would be ok for this and easier, i.e, \begin{tabular} etc not tables. I like the part .. I generate it with JavaScript:) – Yiannis Lazarides Jul 31 '13 at 20:45
  • thanks :) The problem with tables is that my cell's will very frequently have height > \textheight...which I read is impossible to work around with tables (same thing happened with tabular)...ie. the lists on the right will almost always have 20-30-40+ entries – Toadums Jul 31 '13 at 20:49
  • Tried longtable ? – Yiannis Lazarides Jul 31 '13 at 20:52
  • How about \extrarowheight for huge cells? – mafp Jul 31 '13 at 21:09
  • I have tried table, tabular, longtable, minipage...none of them seem to work. And I read that no table-solution is possible... And extrarowheight seems to pose the same problems as just \vspace{} ;( – Toadums Jul 31 '13 at 21:14
3

Placing the enumerate in a minipage environment should do the trick

\noindent
\textbf{Part One - General}
\begin{enumerate}[leftmargin=*,topsep=1ex,itemsep=4ex,label={1.\arabic*}]
  \item
  \begin{minipage}[t]{\dimexpr0.30\textwidth\relax} 
    \raggedright
    \textbf{SECTION INCLUDES}
  \end{minipage}\hspace*{\fill}%'
  \begin{minipage}[t]{\dimexpr0.70\textwidth-2em\relax}
    \begin{enumerate}[align=left, label={.\arabic*}]
        \item Work covered by Contract documents 
        \item Contract Method 
    \end{enumerate}
  \end{minipage}

  \item
  \begin{minipage}[t]{\dimexpr0.30\textwidth\relax} 
    \raggedright
    \textbf{THIS IS A LONGER TITLE}
  \end{minipage}\hspace*{\fill}%'
  \begin{minipage}[t]{\dimexpr0.70\textwidth-2em\relax}
    \begin{enumerate}[align=left, label={.\arabic*}]
        \item Work covered by Contract documents 
        \item Contract Method 
    \end{enumerate}
  \end{minipage}
\end{enumerate}

I'm not sure why you're using the tabular environment.

You mentioned that you tried using a minipage. Be sure to pass the optional argument [t] to get the minipage to line up the baseline of its first line with the baseline of the text it's sitting on.

UPDATE: a much better solution

Here's something that is not so much a hack:

\documentclass{article}
\usepackage{fancyhdr} 
\usepackage[head=41.68335pt]{geometry} 
\usepackage{enumitem} 
\usepackage{indentfirst} 
\pagestyle{empty}
%% I use a box for your "title" and save its width in "\mytitlewidth"
\newlength{\mytitlewidth}
\newlength{\mytopsep}
\newsavebox{\mytitlebox}
%% and environment to handle your list
\newenvironment{enumwithinenum}[1]
  {\setlength{\mytitlewidth}{\dimexpr0.30\textwidth\relax}%%'   
   \setlength{\mytopsep}{2ex}%%'
   %% save the title in a box so we can access its height later to
   %% use to adjust where the next enumerate begins.
   \begin{lrbox}{\mytitlebox}%%'
     \begin{minipage}[t]{\dimexpr\mytitlewidth\relax} 
       \raggedright\strut
       \textbf{#1}
       \par\xdef\tpd{\the\prevdepth}%%'
     \end{minipage}%%'
   \end{lrbox}%%"
   \usebox{\mytitlebox}%%'
   \vspace{-\dimexpr\dp\mytitlebox+\parskip+0.7\baselineskip+\mytopsep\relax}%%'
   \begin{enumerate}[align=left,
                     label={.\arabic*},
                     leftmargin=\dimexpr\mytitlewidth+2em\relax,
                     topsep=\mytopsep,
                    ]
  }
  {\end{enumerate}}
%-@-(1)---------------------------------------------------------------------
\begin{document}

\noindent
\textbf{Part One - General}
\begin{enumerate}[leftmargin=*,topsep=1ex,itemsep=4ex,label={1.\arabic*}]
  \item  \begin{enumwithinenum}{SECTION INCLUDES}
           \item \strut Work covered by Contract documents
           \item Contract Method
           \item Contract Method
           \item Contract Method
           \item Contract Method
           \item Contract Method
           \item Contract Method
           \item Contract Method
           \item Contract Meth
         \end{enumwithinenum}
  \item  \begin{enumwithinenum}{THIS IS A LONGER TITLE}
           \item \strut Work covered by Contract documents 
           \item Contract Method 
         \end{enumwithinenum}
\end{enumerate}

\end{document}

enter image description here

This will work much better. No need to worry about multiple environments when you, in principle, only have one. The one thing that I think you will have to mind with this solution is placing a \strut on the first \item. Also, if you have any unusually tall objects on the first line of the enumerate, then the things will not line up as you need: but this shouldn't be a problem for most sorts of text.

  • I am using the tabular environment because it was the only way I could figure out how to make it so the text on the right was ATMOST X% of the page...If I try to use the minipage, I run into the same issue where if the enumerate is longer than the page, the document doesn't react nicely (see the image attached in my original post) – Toadums Jul 31 '13 at 22:07
  • 1
    @Toadums I've updated my answer to better handle when the list straddles the page. It is a bit of a hack, but it might just do the trick for you. – A.Ellett Jul 31 '13 at 23:12
  • Woooow. Thank you so much!! This seems to be working (I can't break it atleast). I think the first "hacky" solution works better however, because of how I nest the lists (the list on the right can have multiple lists nested within it). I am trying to combine the two for a "less hacky, hacky solution" :) HOW ON EARTH DID YOU GET SO GOOD AT LATEX!?!?!???! ...this is my first time :(. Thanks again!!!!!! – Toadums Jul 31 '13 at 23:50
  • This newer solution should be able to handle nested lists quite well. A couple of points (1) the \vspace might not work probably around page breaks (2) you could define your own strut that you could manually set when needed for extra tall text. The line in this solution about \par\xdef\tpd{\the\predepth} isn't needed; it was just part of an idea I was working on and then decided wasn't necessary. (3) you could possibly do \let\olditem\item and then redefine \item to handle the strut on its own – A.Ellett Aug 1 '13 at 0:06
  • I just noticed something else, the line that reads \setlength{\mytitlewidth}{\dimexpr0.30\textwidth\relax} should really have \linewidth in it instead of \textwidth. Without that change, in a multi-columnar document or if you nest this environment within another list, then the line widths will be incorrect. I'll update my answer with these corrections after I've had more time away from it: invariably, I'll come up with better refinements once I've had some time away from it. – A.Ellett Aug 1 '13 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.