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 have a problem with the spacing after an itemize inside a tabular.

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{framed}
\usepackage[parfill]{parskip}
\usepackage{array,ragged2e}
\usepackage{enumitem}

\definecolor{shadecolor}{RGB}{217,217,217}

\usepackage[left=0.75in,top=1.5in,right=0.75in,bottom=1in]{geometry}

\begin{document}
\lipsum[1]
\lipsum[2]
\begin{snugshade*}{\fontsize{13}{6}\selectfont\textbf{Testing}}\end{snugshade*}
\begin{tabular}{@{}>{\RaggedRight}p{8.64cm}>{\RaggedRight}p{8.64cm}@{}}
\begin{itemize}[topsep=0pt, itemsep=0pt, leftmargin=2ex]
  \item  
  \item Lorem ipsum dolor sit amet;
  \item Lorem ipsum dolor sit amet;
\end{itemize} & 
\begin{itemize}[topsep=0pt, itemsep=0pt, leftmargin=2ex]
  \item 
  \item Lorem ipsum dolor sit amet;
  \item Lorem ipsum dolor sit amet;
  \item Lorem ipsum dolor sit amet;
  %Some text
\end{itemize}
\end{tabular}
\begin{snugshade*}{\fontsize{13}{6}\selectfont\textbf{Testing}}\end{snugshade*}

\end{document}

The problem is the space after the last itemize. It is too big. If i put some text after the last itemize, the space is exactly what i am looking for.

What commands do I have to use to fix that? I know that the easilest way is to put \vspace{-8pt} after the last itemize but the thing is, the content is dynamic so I do not know what is on the last line.

Thanks for you replies.

EDIT: I have added an item in the right cell so the table is not proportional.

share|improve this question
add comment

1 Answer

1. Defining new column type
I found a possible solution in an answer by Danie Els based on code from Donald Arsenauer, see vspace before itemize in a Table cell, tabular vs longtable. Here you are defining new column types for enumerate and itemise, which you utilise by a \multicolumn-command inside the table. If you do not use enumerated lists, you do not need the e-column type.

To get similar control over the spacing of text columns, I have defined a ragged-right text column type, also activated by the multicolumn-command.

For your MWE, the code will be:

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{framed}
\usepackage[parfill]{parskip}
\usepackage{ragged2e,longtable,array,enumitem

\definecolor{shadecolor}{RGB}{217,217,217}

\usepackage[left=0.75in,top=1.5in,right=0.75in,bottom=1in]{geometry}

\makeatletter
%----  Enumerated columns
\newcolumntype{e}[1]{%
    >{\minipage[t]{\linewidth}\let\\\tabularnewline
      \enumerate
      \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
      \setlength{\itemsep}{-\parsep}}%
    p{#1}%
    <{\@finalstrut\@arstrutbox\endenumerate\endminipage}}

%---- Itemized columns
\newcolumntype{i}[1]{%
    >{\minipage[t]{\linewidth}\let\\\tabularnewline
      \itemize
      \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
      \setlength{\itemsep}{-\parsep}}%
    p{#1}%
    <{\@finalstrut\@arstrutbox\enditemize\endminipage}}

%---- Text columns
\newcolumntype{t}[1]{%
    >{\minipage[t]{\linewidth}\let\\\tabularnewline
      \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
      }%
    p{#1}%
    <{\@finalstrut\@arstrutbox\endminipage}}

\makeatother

\begin{document}
\lipsum[1]

\lipsum[2]
\begin{snugshade*}{\fontsize{13}{6}\selectfont\textbf{Testing}}\end{snugshade*}

\begin{tabular}{@{}p{8.64cm}p{8.64cm}@{}}

\multicolumn{1}{@{}i{8.64cm}}{\item This is an empty line  
      \item Lorem ipsum dolor sit amet;
      \item Lorem ipsum dolor sit amet;}
   & 
\multicolumn{1}{@{}i{8.64cm}}{\item But this is not an empty line
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Some text}
\end{tabular}
\begin{snugshade*}{%
  \fontsize{13}{6}\selectfont\textbf{Testing}}
\end{snugshade*}

\begin{tabular}{@{}p{8.64cm}p{8.64cm}@{}}
\multicolumn{1}{@{}t{8.64cm}}{Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;

\smallskip
Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;

\smallskip
Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;Lorem ipsum dolor sit amet;}
  & 
\multicolumn{1}{@{}i{8.64cm}}{\item This line is empty
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     \item Some text}
\end{tabular}
\begin{snugshade*}{%
  \fontsize{13}{6}\selectfont\textbf{Testing}}
\end{snugshade*}    
\end{document}

As you see, you can combine ordinary text in one column and lists in the other, still with correct spacing. The output is: enter image description here

2. Parbox
A simpler solution, with some limitations, is to enclose the itemize-environments in parboxes. To align the text at the top of the parbox, use the optional arguments and give a specific height of the parbox. If you only wants some space, add a \strut after the last itemise in each column. A MWE:

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{framed}
\usepackage[parfill]{parskip}
\usepackage{array,ragged2e}
\usepackage{enumitem}

\definecolor{shadecolor}{RGB}{217,217,217}

\usepackage[left=0.75in,top=1.5in,right=0.75in,bottom=1in]{geometry}

\begin{document}
\lipsum[1]
\lipsum[2]
\begin{snugshade*}{\fontsize{13}{6}\selectfont\textbf{Testing}}\end{snugshade*}
\begin{tabular}{@{}>{\RaggedRight}p{8.64cm}%
                   >{\RaggedRight}p{8.64cm}@{}}
\parbox[c][58pt][t]{8.64cm}{%
   \begin{itemize}[topsep=0pt, itemsep=0pt, leftmargin=2ex]
      \item  
      \item Lorem ipsum dolor sit amet;
      \item Lorem ipsum dolor sit amet;
   \end{itemize}%
 } & 
\parbox[c][58pt][t]{8.64cm}{%
   \begin{itemize}[topsep=0pt, itemsep=0pt, leftmargin=2ex]
     \item 
     \item Lorem ipsum dolor sit amet;
     \item Lorem ipsum dolor sit amet;
     %Some text
   \end{itemize}%
  }
\end{tabular}
\begin{snugshade*}{%
   \fontsize{13}{6}\selectfont\textbf{Testing}}%
 \end{snugshade*}

\end{document}

To overcome the limitations, you have to define a function that calculate the height of the parbox. Her is a starting point:

\settototalheight\foo{\parbox[t]{8.64cm}{\begin{itemize}[topsep=0em, itemsep=0pt, leftmargin=2ex]
  \item Neither is this line
  \item Lorem ipsum dolor sit amet;
  \item Lorem ipsum dolor sit amet;
  \item Lorem ipsum dolor sit amet;
  \item Some text \strut
\end{itemize}}
}

parbox does not accept multiple paragraphs. A work around is to enclose the paragraphs in a minipage of the same width as the parbox inside the \parbox.

Example code:

\settototalheight\fooii{\parbox[t]{8.64cm}{\begin{minipage}[t]{8.64cm}
\lipsum[1-2]
\end{minipage}}
}

Then you have to add 3pt to the variable \fooii and use it as heigh of the parbox you typeset in the table.

This picture is the output from the MWE: enter image description here

share|improve this answer
    
Thanks, but when the right cell is longer than the left, the left content is centered in the cell. I want it to stay on top and the space after the last element is too small. –  Pete Oct 1 '12 at 20:13
    
Thanks for your answer, but unfortunately, it only works on static text. If you add another item, the added item will be under the title due to the "position" option of the parbox. If i only use the t parameter, the parboxes are aligned together but the space after and before the parbox is not good because there's too much space before and not enough after. –  Pete Oct 1 '12 at 20:45
    
Calculating the height of the text would be hard to do due to the non static text. If there is a way to draw the text without putting it to the pdf then retrieve the height and put it to the parameter, i can then set the right margin. It would be hard and long to do, I am sure there's a command to do what i want :) There's also the minipage that is like a \parbox but it has the same problem. –  Pete Oct 1 '12 at 21:22
    
@Sevinung thanks for your answer, unfortunately i am having trouble with the \settototalheight command because it doesn't accept new paragraphs inside. In my dynamic content, i can have paragraphs inside the tabular. Is there a way to accept the paragraphs inside \settototalheight command? or is there a workaround possible? –  Pete Oct 2 '12 at 15:38
    
@Pete See the updated answer. –  Sveinung Oct 3 '12 at 7:04
show 3 more comments

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.