3

I am using a minipage and an enumerate inside a tabular. However, when I do that, the vertical alignment of the "hello" part in the code is lost.

Here is the code:

\documentclass[12pt]{extarticle}

\usepackage{geometry}
\usepackage{array}
\usepackage{enumitem}


\begin{document}

\begin{tabular}{ >{\centering\arraybackslash} m{2cm} | >{\arraybackslash} m{\textwidth} }
    \textit{Hello} & One \newline
    Two \newline
    \textit{{Three}}
    
\begin{minipage}[t]{\linewidth}
        \begin{itemize}[left=2mm, topsep=0pt, label={-}, noitemsep, nosep, partopsep=0pt, after=\strut]
            \item \small Four
            \item \small Five
        \end{itemize}
    \end{minipage} \\
\end{tabular} 

\end{document}

And here is the output

Not vertically aligned

Does anyone know how to make it vertically aligned? Thank you in advance.

4
  • Remark: With m{2cm} and m{\textwidth}, it's certain that your tabular will be too wide. Commented Feb 27, 2023 at 12:17
  • Thank you! I already changed it to m{2cm} and m{11cm}.
    – Uri Toti
    Commented Feb 27, 2023 at 12:20
  • Do you expect Hello to be aligned with Three? Or do you want Hello to be vertically centered in its cell (it's not exactly the same thing)? Commented Feb 27, 2023 at 12:23
  • I expect Hello to be vertically centered in its cell.
    – Uri Toti
    Commented Feb 27, 2023 at 18:01

2 Answers 2

3

Try:

  • remove minipage around list
  • by help of etoolbox define list style in preamble
  • to list style add minipage, see MWE
\documentclass[12pt]{extarticle}
\usepackage{array}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{% <---
    \setlist[itemize]{nosep=0pt,
                     leftmargin=1.5em,
                     label=--,
                     after=\end{minipage},                   
                     before=\begin{minipage}[t]{\linewidth}}
                     }

\begin{document}

\begin{tabular}{ >{\centering\arraybackslash}m{2cm} | m{5cm} }
\textit{Hello}  &   One \newline
                    Two \newline
                    \textit{Three}
                    \begin{itemize}\small 
                \item   Four
                \item   Five
                    \end{itemize}   \\
\end{tabular}

\end{document}

enter image description here

2
  • Using Overleaf editor, everything (the code) appears red in the main document when adding your code. Is there a way of fixing it?
    – Uri Toti
    Commented Feb 27, 2023 at 17:59
  • My MWE as is, work in Overleaf. Tested. However I haven't any clue, how you include proposed solution in your document, how your document is structured etc. Sory, due to lack of information, I can't help you,
    – Zarko
    Commented Feb 27, 2023 at 18:15
2

Here is a workaround with {NiceTabular} of nicematrix. In that environment, which is similar to the classical {tabular} (of the package array), there is a command \Block. In your case, you can put Hello in a mono-cell \Block: that allows the use of the key v-center for that \Block. With that key, the content of the block is mathematically centered in the cell (by using PGF computations).

\documentclass[12pt]{extarticle}

\usepackage{geometry}
\usepackage{enumitem}

\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{ >{\centering\arraybackslash} m{2cm} | >{\arraybackslash} m{11cm} }[hvlines]
    \Block[v-center]{}{\textit{Hello}} & One \newline
    Two \newline
    \textit{{Three}}

\begin{minipage}[t]{\linewidth}
        \begin{itemize}[left=2mm, topsep=0pt, label={-}, noitemsep, nosep, partopsep=0pt, after=\strut]
            \item \small Four
            \item \small Five
        \end{itemize}
    \end{minipage} \\
\end{NiceTabular} 

\end{document}

You need several compilations, because of the PGF/Tikz nodes used by nicematrix under the hood.

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .