0

In the following table (code included below), how can I vertically center the text RowName1? (note that each bulleted list must be within a minipage environment).

example

Code:

\documentclass[letter]{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{cp{2in}p{2in}}
\toprule
          & \multicolumn{1}{c}{\textbf{ColName1}} & \multicolumn{1}{c}{\textbf{ColName2}} \\
\midrule
\textbf{RowName1}
&
\begin{minipage}[t]{\linewidth}
\begin{itemize}
\item 1
\item 2
\end{itemize}
\end{minipage}
&
\begin{minipage}[t]{\linewidth}
\begin{itemize}
\item 1
\item 2
\item 3
\item 4
\end{itemize}
\end{minipage}
\\
\bottomrule
\end{tabular}

\end{document}

ADDENDUM

It would also be useful, if the same effect could be achieved without using minipages. I have tried to do so (see code below), but get the following:

example 2

This is problematic for two reasons: (a) RowName1 is not vertically aligned, and (b) there's extra space before and after the bullet lists.

The code used is:

\documentclass[letter]{article}
\usepackage{booktabs,enumitem,array}

\begin{document}

\begin{tabular}{p{1in}p{2in}p{2in}}
\toprule
          & \multicolumn{1}{c}{\textbf{ColName1}} & \multicolumn{1}{c}{\textbf{ColName2}} \\
\midrule
\textbf{RowName1}
&
\begin{itemize}[topsep=0em, partopsep=0em, parsep=0em, itemsep=0em, leftmargin=1em]\raggedright
\item 1
\item 2
\end{itemize}
&
\begin{itemize}[topsep=0em, partopsep=0em, parsep=0em, itemsep=0em, leftmargin=1em]\raggedright
\item 1
\item 2
\item 3
\item 4
\end{itemize}
\\
\bottomrule
\end{tabular}

\end{document}
  • Do you want the cells with itemize environment to be top aligned, as they are now? – Bernard Nov 21 '15 at 13:49
  • Also, why do the itemize environments have to be in a minipage? – Bernard Nov 21 '15 at 14:18
  • @Bernard: (1) Yes, I need the cells with the itemize environment to be top aligned; (2) The itemize environments need to be in a minipage, as I need to implement some fancy bullets (akin to the compactlist environment described here: tex.stackexchange.com/questions/33070/…) – scaramouche Nov 21 '15 at 15:41
  • the minipage is doing absolutely nothing useful in this context. a p column is already a parbox and parbox and minipage are identical other than minipage footnote support. – David Carlisle Nov 21 '15 at 16:47
  • @DavidCarlisle: I believe I need to minipage as it makes the itemized list start right after the \midrule. If I remove the minipage, some vertical spacing is added (even if using the enumitem package with topsep=0em, partopsep=0em, parsep=0em, itemsep=0em). – scaramouche Nov 21 '15 at 18:23
1

By help of tables nesting and use m column type from package `array:

enter image description here

\documentclass[letter]{article}
    \usepackage{array,booktabs,paralist}%enumitem

    \usepackage{lipsum}

    \begin{document}
\begin{tabular}{c m{2in} m{2in}}
\toprule
          & \hfil \textbf{ColName1} & \hfil \textbf{ColName2} \\
\midrule
\textbf{RowName1}
&   \multicolumn{2}{@{}l@{}}{
    \begin{tabular}{|p{2in}|p{2in}|}
\begin{minipage}[t]{2in}
\begin{itemize}[\textbullet]
\item 1
\item 2
\end{itemize}
\end{minipage}
    &
        \begin{minipage}[t]{2in}
        \begin{itemize}[\textbullet]
        \item 1
        \item 2
        \item 

        3: \lipsum[2]
        \end{itemize}
        \end{minipage}
    \end{tabular}   }
    \\
\bottomrule
\end{tabular}
    \end{document}

Used package \paralistenables simple to define different itemize's label stiles as well adopt left margin of itemize to label width. Of course, if you more familiar withenumitem` package, the same can be achieved with it.

Addendum: If you like to manually centering of first cell's content, that see of the next solution is less over-killed :-). In it is not nested tables, only minipages. Position of first cell content you adjust with maxsimal number of lines in other cells.

\documentclass[letter]{article}
    \usepackage{booktabs,multirow,paralist}%enumitem

    \usepackage{lipsum}

    \begin{document}
\begin{tabular}{c p{2in} p{2in}}
\toprule
          & \hfil \textbf{ColName1} & \hfil \textbf{ColName2} \\
\midrule
\multirow{21}*{\textbf{RowName1}}
    &   \multicolumn{2}{l@{}}{
\begin{minipage}[t]{2in}
    \begin{itemize}[\textbullet]
    \item 1: \lipsum[2]
    \item 2
    \end{itemize}
\end{minipage}\hspace{2\tabcolsep}%
    \begin{minipage}[t]{2in}
        \begin{itemize}[\textbullet]
        \item 1
        \item 2
        \item 3: \lipsum[2]
        \end{itemize}
    \end{minipage}          }\\
\bottomrule
\end{tabular}
    \end{document}

Result is similar as before. This time I omited vertical lines, which in the first case serve only for show columns width in would be in real use omitted.

enter image description here

  • This works, but I wonder if isn't there a more straightforward way of programming this. Having nested tables and minipages seems like an overkill and will be hard to maintain. Essentially, the only I need is to (a) control the vertical alignment of each cell column separately and (b) have itemized lists that start right at the beginning of the cell. – scaramouche Nov 21 '15 at 18:20
  • Tables are very demanding object. To solve particular problems or for make table composition more easy, have been developed a lot of packages. In positioning of cells content you need to remember, that LaTeX consider it as boxes and it align them to tzheir defined baseline. Normaly they are aligned tin respect to top of cells, in case of use m column type to middle of cell. Maybe someone will propose more straightforward s solution ... – Zarko Nov 21 '15 at 18:31
  • @scaramouche, I add to my answer new solution, which not use nested tables. See, if this is more appropriate to you. – Zarko Nov 21 '15 at 19:02
  • This is nicer and does the job, although it is still kludgy (e.g., requires hard coding the length of the first column \multirow{21}, and the intercolumn spacing \hspace{2\tabcolsep}). I imagine that there must be a simpler way to do what I need, so I will leave the question open for a few more days. – scaramouche Nov 21 '15 at 19:34

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.