TransWikia.com

Why are text and lines so close?

TeX - LaTeX Asked by nncnnn on June 30, 2021

begin{table}[htbp]
centering
caption{}label{TABfeatures}
begin{tabular}
{|c|c|c|}
hline
layername& 18layer& xx
hline
ss & multicolumn{2}{c|}{xx}
hline
multirow{3}{*}{fdsfs} &  $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $ & sf 
cline{2-3}
& $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $& fsd
hline
xx & fds & fsd
hline
end{tabular}
end{table}

enter image description here

2 Answers

Here are 4 different versions of your table:

enter image description here

documentclass{article}
usepackage{amsmath}
usepackage{multirow}
usepackage{caption} 

% Only used in first example:
usepackage[column=0]{cellspace}
setlength{cellspacetoplimit}{0.5tabcolsep}
setlength{cellspacebottomlimit}{cellspacetoplimit}

% Only used in second example:
usepackage{makecell}
setcellgapes{0.5tabcolsep}

% Only used in third example:
usepackage{booktabs}

% Only used in last example:
usepackage{nicematrix}
NiceMatrixOptions{cell-space-limits = 0.5tabcolsep}

begin{document}

begin{table}[htbp]
centering
caption{with cellspace}label{TABfeatures}
begin{tabular}{|0c|0c|0c|}
hline
layername& 18layer& xx
hline
ss & multicolumn{2}{c|}{xx}
hline
multirow{3.5}{*}{fdsfs} &  $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $ & sf 
cline{2-3}
& $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $& fsd
hline
xx & fds & fsd
hline
end{tabular}
end{table}


begin{table}[htbp]
centering
makegapedcells
caption{with makecell}label{TABfeatures}
begin{tabular}{|c|c|c|}
hline
layername& 18layer& xx
hline
ss & multicolumn{2}{c|}{xx}
hline
multirow{3.5}{*}{fdsfs} &  $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $ & sf 
cline{2-3}
& $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $& fsd
hline
xx & fds & fsd
hline
end{tabular}
end{table}

begin{table}[htbp]
centering
caption{with booktabs}label{TABfeatures}
begin{tabular}{ccc}
toprule
layername& 18layer& xx
midrule
ss & multicolumn{2}{c}{xx}
addlinespace
multirow{3.5}{*}{fdsfs} &  $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $ & sf 
addlinespace
& $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $& fsd
addlinespace
xx & fds & fsd
bottomrule
end{tabular}
end{table}

begin{table}[htbp]
centering
caption{with nicematrix}label{TABfeatures}
begin{NiceTabular}{ccc}[hvlines]
layername& 18layer& xx
ss & Block{1-2}{xx}
Block{2-1}{fdsfs} &  $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $ & sf 
& $left[begin{array}{l}3 times 3,64  3 times 3,64end{array}right] times 3 $& fsd
xx & fds & fsd
end{NiceTabular}
end{table}

end{document}

Correct answer by leandriis on June 30, 2021

Here I define a mystrut command that takes as argument the number of rows in the matrix that produces the problem; it makes a phantom matrix with as many rows plus one row minus 1ex.

I also add a different solution with an “uncaged” table.

documentclass{article}
usepackage{amsmath}
usepackage{siunitx}
usepackage{multirow} % first solution
usepackage{booktabs} % second solution

sisetup{output-decimal-marker={,}}

% you may need usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{mystrut}{m}
 {
  vphantom
   {
    begin{matrix} prg_replicate:nn { #1 + 1 } {  }[-1ex] end{matrix}
   }
 }
ExplSyntaxOff

begin{document}

begin{tabular}{|c|c|c|}
hline
layername & 18layer & xx
hline
ss & multicolumn{2}{c|}{xx}
hline
multirow{4}{*}{fdsfs}
  & $mystrut{2} begin{bmatrix} 3 times num{3,64}  3 times num{3,64} end{bmatrix} times 3$
  & sf 
cline{2-3}
  & $mystrut{2} begin{bmatrix} 3 times num{3,64}  3 times num{3,64} end{bmatrix} times 3$
  & fsd
hline
xx & fds & fsd
hline
end{tabular}

bigskip

begin{tabular}{@{}ccc@{}}
toprule
layername & 18layer & xx 
cmidrule(r){1-1} cmidrule(l){2-3}
ss & multicolumn{2}{c}{xx}
midrule
fdsfs
  & $ begin{bmatrix} 3 times num{3,64}  3 times num{3,64} end{bmatrix} times 3$
  & sf 
addlinespace
  & $ begin{bmatrix} 3 times num{3,64}  3 times num{3,64} end{bmatrix} times 3$
  & fsd
midrule
xx & fds & fsd
bottomrule
end{tabular}

end{document}

In the second table there is no need for multirow, because it's clear that fsdf refers to the whole block.

enter image description here

Answered by egreg on June 30, 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