8

Here is the table I am trying to create, which contains the

   \documentclass{article}
    \usepackage{booktabs,tabularx}
    \newcolumntype{Y}{>{\raggedright\arraybackslash}X}
     \newcolumntype{T}{>{\raggedright\arraybackslash}p{2.5cm}}



         \begin{document}
         \begin{table*}
            \caption{My table caption}
            \label{tab:Table1}
              \begin{tabularx}{\textwidth}{@{}TX@{}}
               \toprule
                 Column1 & Case of Column2\\
                \midrule
                 column 1 value & 
                  \begin{itemize}
                  \vspace*{-\baselineskip}
                  \item multiline item text multiline item text multiline item text multiline item text multiline item text
                  \vspace*{-\baselineskip}
                  \item multiline item text multiline item text
                  \vspace*{-\baselineskip}
                  \end{itemize}  \\
               \bottomrule
              \end{tabularx}
              \end{table*}
             \end{document}

Although this is not an elegant solution it eliminates the space before, after and between the bullet points regardless of the spacing scheme in rest of the document. Since the item text itself is multiline text the line spacing is a lot.

Can anyone suggest an elegant solution to create a very compact bulleted points within a table cell. I experimented with the solution given here How to remove the whitespace BEFORE itemize/enumerate?

  • 1
    The question you link to uses \begin{itemize}[noitemsep] (make sure to add \usepackage{enumitem}). Does that not do the trick? – Henk Metselaar Dec 14 '17 at 4:49
  • Also, your code fragment can't be compiled because it misses \documentclass[]{} and \begin{document}/\end{document}. – Henk Metselaar Dec 14 '17 at 4:52
  • thanks @HenkMetselaar when I use \begin{itemize}[noitemsep] the compilation stops with the following message Package enumitem Error: (1) undefined. See the enumitem package documentation for explanation. Type H <return> for immediate help. ... l.253 \begin{enumerate}[(1)] and when I press enter it continues to compile. – Prem Dec 14 '17 at 4:59
  • Please do not post code fragments, but always minimal compilable code samples (MWE) to help us help you. – TeXnician Dec 14 '17 at 5:32
  • @TeXnician i have edited the code and now its MWE. Can you please suggest the workaround to my issue?? – Prem Dec 14 '17 at 5:42
10

You may achieve your formatting objective by (a) loading the enumitem package and using some of its capabilities -- specifically, setting the options nosep, wide=0pt, leftmargin=*, and after=\strut -- and (b) encasing the itemize environment inside aminipage` environment.

Aside: If the itemize environment were not contained in a table column, setting the option nosep would suffice to suppress the whitespace space padding above and below the itemize environment (as well as the whitespace between the items). However, because the itemize environment occurs inside the column of a tabularx environment, it turns out to be necessary to embed the itemize environment in a minipage environment.

Finally, in case you're curious to find out what the option after=\strut does: It ensures that the bottom row of the itemize environment isn't too close to the horizontal line drawn by \bottomrule. Note that in your example, the final item row contains no words with characters with descenders (such as g, p, q, and y). Without the \strut, the material in the bottom line of the itemize environment would simply look to be too close to the line drawn by \bottomrule.

enter image description here

\documentclass{article}
\usepackage{booktabs,tabularx,enumitem,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}

\begin{document}
\begin{table}
\caption{My table caption}
\label{tab:Table1}
\begin{tabularx}{\textwidth}{@{} lY @{}}
   \toprule
   Column1 & Column2\\
   \midrule
   column 1 value & 
   \begin{minipage}[t]{\linewidth}
   \begin{itemize}[nosep, wide=0pt, leftmargin=*, after=\strut]
   \item multiline item text multiline item text multiline    
         item text multiline item text multiline item text
   \item multiline item text multiline item text
   \end{itemize}  
   \end{minipage}\\
   \bottomrule
\end{tabularx}
\end{table}
\end{document}
  • In the place of \leftmargini=10pt, it would be simpler to add the options [wide=0pt, leftmargin=*]. – Bernard Dec 14 '17 at 9:56
  • @Bernard - Excellent suggestion! :-) I've edited the answer accordingly. – Mico Dec 14 '17 at 10:04
  • You made a small mistake: wide alone adds an indent (of 1em, I believe) before the bullet. It should be wide=0pt to align the bullet with the C above. – Bernard Dec 14 '17 at 10:15
  • @Bernard - I get the exact same alignment with wide and wide=0pt. Put differently, I notice no extra indent (of 1em or whatever) before the bullet in case I just specify wide. – Mico Dec 14 '17 at 11:14
  • 1
    Strange… Testing on thebasis of your code, I've just discovered it is specific to thetable environment. I rember having to specify 0pt a few years ago. Maybe something has changed in the code of enumitem? In any case, outside of tabular, you have to specify it. – Bernard Dec 14 '17 at 11:32
6

Set the list using a tabular:

enter image description here

\documentclass{article}

\usepackage{booktabs,tabularx}

\newcolumntype{T}{>{\raggedright\arraybackslash}p{2.5cm}}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{ @{} T X @{} }
  \toprule
  Column1 & Case of Column2 \\
  \midrule
  column 1 value & 
  \begin{tabular}[t]{ @{\makebox[1.5em][l]{\textbullet}} p{\dimexpr\linewidth-1.5em} @{} }
    multiline item text multiline item text multiline item text multiline item text multiline item text \\
    multiline item text multiline item text
  \end{tabular} \\
  \bottomrule
\end{tabularx}

\end{document}

The inner-tabular is set similar to a list, spreading the full \linewidth of the outer-tabularx X-column and is [t]op-aligned to ensure it aligns vertically with the surrounding cell entries.

Adjust the width for the \makebox to change the bullet alignment.


For an enumerated list of items, you can use the regular enumi counter (for the first level of enumeration inside an enumerate environment:

enter image description here

\documentclass{article}

\usepackage{booktabs,tabularx}

\newcolumntype{T}{>{\raggedright\arraybackslash}p{2.5cm}}

\newcommand{\settabenum}{\makebox[1.5em][l]{%
  \refstepcounter{enumi}%
  \xdef\@currentlabel{\@currentlabel}%
  \theenumi.}}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{ @{} T X @{} }
  \toprule
  Column1 & Case of Column2 \\
  \midrule
  column 1 value & \setcounter{enumi}{0}% Reset the enumeration counter, if needed
  \begin{tabular}[t]{ @{\settabenum} p{\dimexpr\linewidth-1.5em} @{} }
    multiline item text multiline item text multiline item text multiline item text multiline item text \\
    multiline item text multiline item text
  \end{tabular} \\
  \bottomrule
\end{tabularx}

\end{document}

In the above example there is no need to \setcounter{enumi}{0}, but if you have other enumerate lists in your document, you may have to reset this within your tabular.

If you want to be able to reference some of the items, then we have to use a different setup:

enter image description here

\documentclass{article}

\usepackage{booktabs,tabularx}

\newcolumntype{T}{>{\raggedright\arraybackslash}p{2.5cm}}

\newcommand{\settabenum}{%
  \refstepcounter{enumi}%
  \makebox[0pt][r]{\makebox[1.5em][l]{%
  \theenumi.}}}

\begin{document}

See item~\ref{second}.

\bigskip

\noindent
\begin{tabularx}{\textwidth}{ @{} T X @{} }
  \toprule
  Column1 & Case of Column2 \\
  \midrule
  column 1 value & \setcounter{enumi}{0}% Reset the enumeration counter, if needed
  \begin{tabular}[t]{ @{\hspace{1.5em}} >{\settabenum} p{\dimexpr\linewidth-1.5em} @{} }
    multiline item text multiline item text multiline item text multiline item text multiline item text \\
    multiline item text multiline item text \label{second}
  \end{tabular} \\
  \bottomrule
\end{tabularx}

\end{document}
  • Hi @Werner Thanks a lot for the solution. This is what i exactly needed. :) – Prem Dec 14 '17 at 7:03
  • hi @Werner I really like your solution. What if i need an ordered list? Will it be a minor change in the code? – Prem Dec 17 '17 at 23:13
  • 1
    @Prem: See my updated answer. – Werner Dec 18 '17 at 0:30

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.