1

I am making a table with multiple rows and I need to vertically align the contents of the cells that I show in the image. I've tried a few things like modifying the \vspace but can't get it to work properly. Does anyone know how can I do ?? Thank you very much!!

\usepackage{tabularx}
\usepackage{multirow}
\usepackage{lipsum}

\begin{document}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{table}[!ht]
\centering
\begin{tabularx}{\textwidth}{|p{1cm}|Y|m{2cm}|}
\hline
\textbf{Task} & \textbf{Description} & \textbf{Points} \\ \hline
\multirow{2}{1cm}{\textbf{TX.x}} & \multicolumn{1}{Y|}{\textbf{Test Header}} & \multirow[b]{2}{2cm}{\centering Example} \\ \cline{2-2}
 & \multicolumn{1}{X|}{\lipsum[1]} &  \\ \hline
\end{tabularx}
\end{table}

\end{document}

ab

1
  • \multirow{14} should work in this specific case. The number refers to the number of lines of text as opposed to the number of table rows.
    – leandriis
    Jul 3, 2020 at 15:56

4 Answers 4

2

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{lipsum}

\begin{document}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{table}[!ht]
\centering
\begin{tabularx}{\textwidth}{|p{1cm}|Y|m{2cm}|}
\hline
\textbf{Task} & \textbf{Description} & \textbf{Points} \\ \hline
\multirow{17}{1cm}{\textbf{TX.x}} & \multicolumn{1}{Y|}{\textbf{Test Header}} & \multirow{17}{2cm}{\centering Example} \\ \cline{2-2}
 & \multicolumn{1}{X|}{\lipsum[1]} &  \\ \hline
\end{tabularx}
\end{table}

\end{document}
3
  • 1
    Why 17 in \multirow{17}?
    – leandriis
    Jul 3, 2020 at 16:38
  • the centre column has more rows than two --therefore an approximation to center the side columns--if the centre coln also had two rows probably not required
    – js bibra
    Jul 3, 2020 at 16:41
  • The contents in the middle column occupy a total of 19 rows. If you specify \multirow{17}, the contents in teh first and last column will not be exactly vertically centered.
    – leandriis
    Jul 3, 2020 at 17:26
3

You don't really need to use multirow. Here is a simpler code, redefining the X column type as m{} instead of p:

\documentclass[twocolumn]{article}

\usepackage{tabularx, ragged2e, caption, lipsum}
\setlength{\extrarowheight}{2pt}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}

\begin{document}

\begin{table}[!ht]
\centering
\begin{tabularx}{\textwidth}{|>{\centering\bfseries}p{1cm}|X|>{\centering\bfseries\arraybackslash}m{2cm}|}
\hline
Task & \thead{Description} & Points \\ \hline
 & \thead{Test Header} & \\ \cline{2-2}
TX.x & \lipsum[1] & Example \\
 \hline
\end{tabularx}
\end{table}

\end{document} 

enter image description here

3

With multirow, you have to count the number of lines. If you want to specify a position relatively to a number of rows (of the tabular), we may use {NiceTabular} of nicematrix and its command \Block. Moreover, you only have to use the key hvlines to draw all the expected rules.

The X column is similar to the X column of {tabularx} of the package tabularx (you need nicematrix ≥ 6.0).

\documentclass{article}
\usepackage{lipsum}
\usepackage{nicematrix}

\begin{document}

\begin{table}[!ht]
\centering
\begin{NiceTabular}{w{c}{1cm}Xw{c}{2cm}}[hvlines]
\RowStyle{\bfseries}
Task & \centering Description & Points \\ 
\Block{2-1}{TX.x} & \centering \bfseries Test Header & \Block{2-1}{Example} \\ 
 & \lipsum[1] &  \\ 
\end{NiceTabular}
\end{table}

\end{document}

Output of the above code

2
  • multirow cells have their content at the vertical center of cell. It is at center of declared number of the text lines in adjacent table columns, which are spanned by them
  • In your MWE you declare only two text lines, but there are 14 of them
  • Recent version of multirow cells has option =, which overtake declared width of column (see MWE below).

Off-topic:

  • For column headers is used \thead macro from the makecell package.
  • For additional vertical space around cells' contents is used \makegapedcells macro, defined also defined in makecell package.
  • Removed are all multicolumn{1}{...}{...} cells, They are superfluous.
\documentclass{article}
\usepackage{geometry}
\usepackage{makecell, multirow, tabularx} % <---
\renewcommand\theadfont{\normalsize\bfseries} % <---
\renewcommand\theadgape{} % <---
\usepackage{lipsum}

\begin{document}
    \begin{table}[ht]
    \centering
    \setcellgapes{3pt} % <---
    \makegapedcells % <---
\begin{tabularx}{\textwidth}{|p{1cm}|X|p{2cm}|} % <---
    \hline
\thead{Task}    & \thead{Description}   & \thead{Points}  % <---                       \\
    \hline
\multirow{14}{=}{\thead{TX.x}} % <---
                & \thead{Test Header}   & \multirow{14}{=}{\centering Example}  \\ 
    \cline{2-2}
                & \lipsum[1]            &                                       \\ 
    \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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