4

I have a tabularx table using multirow and with all columns vertically centered. Here's the table:

\usepackage{multirow,tabularx}

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\def\tabularxcolumn#1{C{#1}}

\begin{tabularx}{\textwidth}{|C{3cm}|X|C{3cm}|N}
\hline
\multirow{2}{*}{\includegraphics[width=2.5cm]{logo}} &
\multirow{2}{*}{\Large{Title of this document}} &
    Doc.ref. &\\
\cline{3-3}
& & Revision &\\
\hline
\end{tabularx}%

I am looking for a way to force a minimum row height for a specific row in this table, but everything I tried didn't work for one reason or another.

  • \setlength{\extrarowheight}{1cm} breaks vertical alignment of the rightmost cells (they will not be vertically centered anymore)
  • Adding extra space when breaking the rows, e.g. &\\[1cm] breaks vertical alignment of the first two cells (the ones using \multirow)
  • Increasing the array stretch factor (e.g. \renewcommand{\arraystretch}{2.5}) doesn't seem to play nice with vertical alignments (it seems to push the contents of the cells below the vertical center)

Update: Manually adjusting positions will not work as this is a template -- the actual document title is filled in later and may take one or two lines.

Any other ideas?

1
  • Couldn't one add a zero-width column, without border and a forced height?
    – zrajm
    Apr 10, 2020 at 10:09

1 Answer 1

3

REVISED solution, which eliminates the multirow, instead using a nested tabulars. RE-REVISED to consolidate everything into \makemytable{height}, just to allow easier play-testing with various heights.

Here I just \addstackgap[<length>]{object} in order to add a vertical buffer above and below objects on that row. Buffer size added depends automatically upon the height of the inserted image.

\documentclass{article}
\usepackage{graphicx,stackengine}
\usepackage{multirow,tabularx}
\newsavebox\customimg
\def\bufferA{.5\dimexpr\ht\customimg+\dp\customimg+1\normalbaselineskip}
\def\bufferB{.25\dimexpr\ht\customimg+\dp\customimg+.5\normalbaselineskip}
\def\setimgheight#1{\savebox\customimg{%
  \raisebox{\dimexpr-\height+.5\normalbaselineskip} %
  {\includegraphics[width=2.5cm,height=#1]{example-image}}}
}
\def\makemytable#1{\setimgheight{#1}
  \begin{tabularx}{\textwidth}{|C{3cm}|X|@{\hspace{0pt}}C{3cm}@{\hspace{0pt}}|N}
  \hline
  \usebox{\customimg} &
  \addstackgap[\bufferA]{\Large{Title of this document}} &
  \begin{tabular}{@{\hspace{0pt}}c@{\hspace{0pt}}}
      \addstackgap[\bufferB]{\makebox[3.0cm]{Doc.ref.}} \\
  \hline
   \addstackgap[\bufferB]{Revision} \\
  \end{tabular}&\\
  \hline
  \end{tabularx}\par\medskip
}
\begin{document}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\def\tabularxcolumn#1{C{#1}}
\makemytable{1cm}
\makemytable{3cm}
\makemytable{5cm}
\end{document}

enter image description here

7
  • But is it necessary to specify all of the gaps manually? The problem is that this is for a template; the "title of the document" will be filled in later, and it may take more than one row. I tried using addstackgap only to the "image" cell or to the "doc.ref" and "revision" cells and it still didn't work..
    – Grodriguez
    Jun 25, 2015 at 17:02
  • @Grodriguez you did not mention that the requirement is for a template, which implies no manual intervention. My solution fails that test. For that reason, I shall delete my answer. Jun 25, 2015 at 17:24
  • Sorry. I did not realize that this would make a difference. I am still surprised there is no easy solution to what it would seem to be a very common problem..
    – Grodriguez
    Jun 25, 2015 at 17:28
  • @Grodriguez Please see revision. Jun 25, 2015 at 18:34
  • Wow. Lots to study here :-)
    – Grodriguez
    Jun 25, 2015 at 19:16

You must log in to answer this question.

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