TransWikia.com

Unwanted space at bottom of tabularx cell

TeX - LaTeX Asked by shilch on February 14, 2021

While trying to solve another issue of mine, I encountered the following issue:

In a tabularx cell there is unwanted space getting inserted at the bottom when using the following code:

documentclass[border=1cm]{standalone}

usepackage{tikz}
usepackage{tabularx}

renewcommand{tabcolsep}{0mm}
tikzset{inner sep=0mm}

begin{document}
begin{tabularx}{10cm}{|X|X|}
    hline
    rule{2cm}{2cm} & rule{2cm}{2cm} 
    hline
    tikz{node[fill,minimum width=2cm,minimum height=2cm]{};} & tikz{node[fill,minimum width=2cm,minimum height=2cm]{};} 
    hline
    Also get it & with text 
    hline
end{tabularx}
end{document}

Picture:

picture

I suppose that space is for the stuff that belongs below the baseline of a text. Since I only want to put tikzpictures into the cells, how can I disable this behaviour?

Thanks in advance!

2 Answers

The space is the depth of the strut.

Use baseline:

documentclass[border=1cm]{standalone}

usepackage{tikz}
usepackage{tabularx}

renewcommand{tabcolsep}{0mm}
tikzset{inner sep=0mm}

begin{document}
begin{tabularx}{10cm}{|X|X|}
    hline
    rule{2cm}{2cm} & rule{2cm}{2cm} 
    hline
    tikz[baseline]{node[fill,minimum width=2cm,minimum height=2cm]{};} &
    tikz[baseline]{node[fill,minimum width=2cm,minimum height=2cm]{};} 
    hline
    Also get it & with text 
    hline
end{tabularx}
end{document}

enter image description here

Correct answer by egreg on February 14, 2021

There's absolutely no need in the tabular environment for either the vertical lines or the interior horizontal lines. I suggest you load the booktabs package and use its toprule and bottomrule macros to create well-spaced exterior, i.e., top and bottom, horizontal lines.

enter image description here

documentclass{article}
usepackage{tikz,tabularx,booktabs}
renewcommand{tabcolsep}{0mm}
tikzset{inner sep=0mm}

begin{document}
begin{center}
begin{tabularx}{10cm}{XX}
    toprule
    rule{2cm}{2cm} & 
    rule{2cm}{2cm} 
    %hline
    tikz{node[fill,minimum width=2cm,minimum height=2cm]{};} &
    tikz{node[fill,minimum width=2cm,minimum height=2cm]{};} 
    %hline
    Also get it & with text 
    bottomrule
end{tabularx}
end{center}
end{document}

Answered by Mico on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP