# Can't center vertically text in table with enumerate in one column

Code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{array}
\begin{document}
\begin{tabular}{ |m{0.8cm}| p{3cm} |c| }
\hline
1
&
\begin{enumerate}
\setlength{\leftmargin}{0pt}
\item line 1
\item line 2
\end{enumerate}
&
2\\
\hline
\end{tabular}
\end{document}


Output:

My goal was to use c environment for left and right columns and vertically center their content.

In this answer, @Werner says, that to center the content vertically, I must use m{<width>} column type from array package. So, I tried it for the 1-st column. But with enumerate it didn't work for some reason.

How can center columns 1 and 3 vertically? Ideally, keeping c column type for automatic width, but even m is ok, if it's impossible.

You can define a new column type to automatically add the minipage; then it depends on what material you want to insert in that column. If all cells will contain enumerate environments, you can do this way:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{array,enumitem}
\newcolumntype{M}[1]{%
>{\begin{minipage}{#1}}
m{#1}
<{\end{minipage}}
}
\newenvironment{tenumerate}
{\vspace{\topsep}\vspace{-\parsep}\begin{enumerate}[leftmargin=*]}
{\end{enumerate}\vspace{\topsep}}

\begin{document}
\begin{tabular}{|m{0.8cm}|M{3cm}|c|}
\hline
1
&
\begin{tenumerate}
\item line 1
\item line 2
\end{tenumerate}
&
2\\
\hline
\end{tabular}
\end{document}


Or you can add the two \vspace{\topsep} commands (which can be any dimension as you like instead of \topsep) to all cells in the column, then do

\newcolumntype{M}[1]{%
>{\begin{minipage}{#1}\vspace{\topsep}}
m{#1}
<{\csname par\endcsname\vspace{\topsep}\end{minipage}}
}


(the \csname par\endcsname is to trick \newcolumntype into not thinking \par really appears).

Other variations are possible, but the final setup depends on the material you have to put into the table.

Simply put the enumerate environment inside another minipage,

  \begin{minipage}[c]{30.0mm}
\begin{enumerate}
\setlength{\leftmargin}{0pt}
\item line 1
\item line 2
\end{enumerate}
\end{minipage}


And all your columns are vertically centered,

Definitely, other tweaks can be carried out to improve appearance. For example if you want to add some space (margins) before or after the enumeration, simply put a \vspace* command before or after.

Also, you may want to save the column width in some length (\newlength{cwidth} or some such) and use it to specify the width in tabular and in minipage.

• How can I add vertical margins to the minipage? – user4035 Oct 5 '13 at 10:12
• @user4035 Do you mean something like top or bottom margins? If that is so, please see my edited post. Please get back to me if you want something else. – Masroor Oct 5 '13 at 13:23