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:
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!
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}
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.
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP