0

I've got a merged column inside a table using multicolumn. I would like the text in this multicolumn to be centered vertically. This is the MWE:

\documentclass[14pt]{article}
\usepackage[left=2.54cm, right=2.54cm, top=3.17cm, bottom=3.17cm]{geometry}
\usepackage{tabu,longtable}

\begin{document}
    \begin{longtabu} to \textwidth {|p{0.1\textwidth}|X|}
        \hline
        \textbf{1.} & stuff \\ \hline
        \textbf{2.} & stuff \\ \hline
        \multicolumn{2}{|l|}{\large{\textbf{Reports}}} \\[3ex] \hline
    \end{longtabu}
\end{document}

Which gives:

enter image description here

I've tried various combinations of things including defining a column type using:

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

and:

\usepackage{array}
\multicolumn{2}{|M{1cm}|}{\large{\textbf{Reports}}} \\[3ex] \hline

But this does not work. I've seen lots of examples using tabular but I need my table to span multiple pages.

3
  • 1
    tabu is buggy and unmaintained. See the readme here github.com/tabu-issues-for-future-maintainer/tabu. I no longer try to answer questions using tabu. So consider if you really want to use it. Dec 16 '19 at 11:33
  • I've used tabu as I couldn't find a way to make longtable scale to textwidth easily and automatically scale the width of the last column accordingly. Dec 16 '19 at 11:47
  • 1
    You could try ctan.org/pkg/xltabular. But I normally simply calculate the width. In your example eg. the second column could use p{\dimexpr 0.9\textwidth-4\tabcolsep -3\arrayrulewidth} (but I would use less rules ...) Dec 16 '19 at 12:07
1

The new LaTeX3 package tabularray is an alternative to the outdated tabu package: vertical centering is easy inside longtblr environemnt.

\documentclass[14pt]{article}

\usepackage[left=2.54cm, right=2.54cm, top=3.17cm, bottom=3.17cm]{geometry}
\usepackage{tabularray}

\begin{document}

\begin{longtblr}[
  caption = {Long Title},
  label = {tblr:test},
]{
  colspec = {|t{0.1\textwidth}|X|},
  column{1} = {font=\bfseries},
  row{3} = {3em},
  cell{3}{1} = {c=2}{m,font=\large\bfseries}, % multicolumn
  hlines,
}
  1.      & stuff \\
  2.      & stuff \\
  Reports &       \\
\end{longtblr}

\end{document}

enter image description here

0

I would like to see a more general solution, but this worked for me:

\documentclass[14pt]{article}
\usepackage[left=2.54cm, right=2.54cm, top=3.17cm, bottom=3.17cm]{geometry}
\usepackage{tabu,longtable}
\begin{document}
    \begin{longtabu} to \textwidth {|p{0.1\textwidth}|X|}
        \hline
        \textbf{1.} & stuff \\ \hline
        \textbf{2.} & stuff \\ \hline
        \multicolumn{2}{|l|} \\[1ex]
        \multicolumn{2}{|l|}{\large{\textbf{Reports}}} \\[3ex] \hline
    \end{longtabu}
\end{document}

I've added an empty row scaled to the right size above the row whose height I changed.

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.