TransWikia.com

Line spacing in table without using booktabs

TeX - LaTeX Asked by Alexandre Simard on January 5, 2021

I’m having a problem with a table I’m trying to do. This is the code I currently have :

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}

renewcommand{l}{left}
renewcommand{r}{right}
renewcommand{d}{displaystyle}
newcommand{virg}{:,:}

renewcommand{arraystretch}{2}
usepackage{multirow}

begin{document}

begin{center}
begin{tabular}{cc|c|c|}
cline{3-4}
 &  & multicolumn{2}{c|}{Individu 1}  cline{3-4} 
 &  & Colombe & Faucun  hline
multicolumn{1}{|c|}{multirow{2}{*}{Individu 2}} & Colombe & (dl(frac{g}{2} virg frac{g}{2}r)) & ((g virg 0))  cline{2-4} 
multicolumn{1}{|c|}{} & Faucon  & ((0 virg g)) & (dl(frac{g-c}{2} virg frac{g-c}{2}r))  hline
end{tabular}
end{center}

end{document}

The result I want is a table which contains fractions. But the lines are way too narrow and the fractions touch the line on top and on the bottom of them.

I tried to ajust the arraystretch to 2 (using renewcommand{arraystretch}{2}) but this messes up the vertical centering of the text in the cell, as it only adds space on top of the text. Is there any way to fix this issue?

Note : I cannot use booktabs because the table I’m drawing must have vertical lines. It should look like this:

Made in word, the font and the spacing is not exactly what I needAnd this is what I currently have :
enter image description here

(Made in word, the font and the spacing is not exactly what I need)

4 Answers

Do yourself a favor and don't redefine l, r and d. You may find them handy shortcuts, but you'll be in great trouble in case the standard meaning of those commands (which have to do with accents) is needed.

The setting of the widths could be made based on the width of the wide pair, but it just take a moment to guess the good one.

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}

usepackage[T1]{fontenc}
usepackage{babel}
usepackage{amsmath}
usepackage{multirow,array}

%usepackage{xparse} % not needed with LaTeX 2020-10-01 or later

NewDocumentCommand{pair}{s O{} >{SplitArgument{1}{,}}m }{%
  IfBooleanTF{#1}
    {left(makepair#3right)}
    {mathopen{#2(}makepair#3mathclose{#2)}}%
}
NewDocumentCommand{makepair}{ m m }{%
  #1mspace{4mu}{,}mspace{4mu}#2%
}

newcommand{adj}[1]{ensuremath{vphantom{#1|}}ignorespaces}

begin{document}

begin{center}
begin{tabular}{|c|c|w{c}{7em}|w{c}{7em}|}
cline{3-4}
multicolumn{2}{c|}{adj{Big}} & multicolumn{2}{c|}{Individu 1} 
cline{3-4} 
multicolumn{2}{c|}{adj{Big}} & Colombe & Faucon 
hline
multirow{3}{*}{Individu 2}
& adj{bigg} Colombe & (pair[Big]{dfrac{g}{2},dfrac{g}{2}}) & (pair{g,0}) 
cline{2-4}
& adj{bigg} Faucon  & (pair{0,g}) & (pair[Big]{dfrac{g-c}{2},dfrac{g-c}{2}}) 
hline
end{tabular}
end{center}

end{document}

What's adj{Big}? I adds a strut like Big|. For the rows with the big pairs, I used adj{bigg}, because the parentheses are already Big.

Note also the syntax pair{x,y} which is easier than (xvirg y).

Why not using left and right? Look closely at your output and you'll notice that the sizes of the large parentheses in the top row and in the bottom row are different. The reason is the presence of the minus sign in the bottom row, believe it or not.

enter image description here


A different suggestion.

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}

usepackage[T1]{fontenc}
usepackage{babel}
usepackage{amsmath}
usepackage{booktabs,array}

%usepackage{xparse} % not needed with LaTeX 2020-10-01 or later

NewDocumentCommand{pair}{s O{} >{SplitArgument{1}{,}}m }{%
  IfBooleanTF{#1}
    {left(makepair#3right)}
    {mathopen{#2(}makepair#3mathclose{#2)}}%
}
NewDocumentCommand{makepair}{ m m }{%
  #1mspace{4mu}{,}mspace{4mu}#2%
}

begin{document}

begin{center}
begin{tabular}{c w{c}{7em} w{c}{7em}}
toprule
Individu 2 & multicolumn{2}{c}{Individu 1} 
cmidrule(lr){2-3}
& Colombe & Faucon 
midrule
Colombe & (pair[Big]{dfrac{g}{2},dfrac{g}{2}}) & (pair{g,0}) 
addlinespace
Faucon  & (pair{0,g}) & (pair[Big]{dfrac{g-c}{2},dfrac{g-c}{2}}) 
bottomrule
end{tabular}
end{center}

end{document}

enter image description here

Correct answer by egreg on January 5, 2021

Like this?

enter image description here

One way is use of the instruction makegapedcells defined in the makecell package, which add vertical space above/below cells' contents:

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}

renewcommand{l}{left}
renewcommand{r}{right}
renewcommand{d}{displaystyle}
newcommand{virg}{:,:}

renewcommand{arraystretch}{2}
usepackage{makecell, multirow}

begin{document}

begin{center}
setcellgapes{5pt}
makegapedcells
begin{tabular}{cc|c|c|}
cline{3-4}
 &  & multicolumn{2}{c|}{Individu 1}  cline{3-4}
 &  & Colombe & Faucun  hline
multicolumn{1}{|c|}{multirow{2}{*}{Individu 2}} & Colombe & (dl(frac{g}{2} virg frac{g}{2}r)) & ((g virg 0))  cline{2-4}
multicolumn{1}{|c|}{} & Faucon  & ((0 virg g)) & (dl(frac{g-c}{2} virg frac{g-c}{2}r))  hline
end{tabular}
end{center}

end{document}

Addendum: Considering @Mico comment, i make the following changes to above solution:

  • Use amsmath package for commanddfrac, by which is replaced your definition to use displaystyle at fractions.
  • remove definition for l, r, it is better to write left and right.
  • to make third and fourth rows aequal height, the vphantom{-} is added to the fraction in third rows. With its, the fracions height in bot rows become equal height.

New MWE:

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}

usepackage{amsmath}
newcommand{virg}{:,:}
usepackage{makecell, multirow}

begin{document}

begin{center}
setcellgapes{5pt}
makegapedcells
begin{tabular}{cc|c|c|}
    cline{3-4}
    &           & multicolumn{2}{c|}{Individu 1}    cline{3-4}
    &           & Colombe   & Faucun  hline
multicolumn{1}{|c|}{multirow{4}{*}{Individu 2}} 
    & Colombe   & (left(dfrac{g}{2}virgdfrac{gvphantom{-}}{2}right)) 
                            & ((gvirg0))          cline{2-4}
multicolumn{1}{|c|}{} 
    & Faucon    & ((0 , g)) 
                            & (left(dfrac{g-c}{2}virgdfrac{g-c}{2}right))  hline
end{tabular}
end{center}

end{document}

enter image description here

Answered by Zarko on January 5, 2021

I think the tool of choice for this problem is cellspace which ensures a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx):

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}
usepackage{amsmath} 
usepackage{cellspace}
setlength{cellspacetoplimit}{5pt}
setlength{cellspacebottomlimit}{5pt}
renewcommand{l}{left}
renewcommand{r}{right}
renewcommand{d}{displaystyle}
newcommand{virg}{:,:}

renewcommand{arraystretch}{2}
usepackage{multirow}

begin{document}

begin{center}
begin{tabular}{cc|Sc|Sc|}
cline{3-4}
 & & multicolumn{2}{c|}{Individu 1}  cline{3-4}
 & & Colombe & Faucun  hline
multicolumn{1}{|c|}{multirow{2}{*}{Individu 2}} & Colombe & (Bigl(dfrac{g}{2} virg dfrac{g}{2}Bigr)) & ((g virg 0))  cline{2-4}
multicolumn{1}{|c|}{} & Faucon & ((0 virg g)) & (Bigl(dfrac{g-c}{2} virg dfrac{g-c}{2}Bigr))  hline
end{tabular}
end{center}

end{document}

enter image description here

Answered by Bernard on January 5, 2021

If I understand your requirements correctly, the first tabular solution below should work, as all four columns have the exact same widths and all four rows have the same heights. However, I think that the second tabular solution below looks (even) better.

enter image description here

documentclass[12pt,letterpaper,french]{extarticle}
usepackage[margin=.75in]{geometry}
usepackage{multirow,array,babel,amsmath}
newcommandmyfrac{Bigl( frac{g-c}{2}, frac{g-c}{2} Bigr)}
newlengthmylen
settowidthmylen{$displaystylemyfrac$}
newcolumntype{C}{>{$displaystyle}w{c}{mylen}<{$}}
newcommandtallstrut{vphantom{biggl|}} % typographic struts
newcommandshortstrut{smash[b]{vphantom{Bigl|}}}

begin{document}
begin{table}
centering

begin{tabular}{|w{c}{mylen}|w{c}{mylen}|C|C|}
cline{3-4}
multicolumn{1}{c}{} & & multicolumn{2}{c|}{Individu 1$tallstrut$} 
cline{3-4}
multicolumn{1}{c}{} & & $Colombe$tallstrut & $Faucon$tallstrut 
hline
multirow{3}{*}{Individu 2} 
  & Colombe & Bigl( frac{g}{2}, frac{g}{2} Bigr)tallstrut & (g,0) 
cline{2-4}
  & Faucon & (0,g)tallstrut & myfrac 
hline
end{tabular}

bigskipbigskip

begin{tabular}{|c|c|C|C|}
cline{3-4}
multicolumn{1}{c}{} & & multicolumn{2}{c|}{Individu 1$shortstrut$} 
cline{3-4}
multicolumn{1}{c}{} & & $Colombe$shortstrut & $Faucon$ 
hline
multirow{3}{*}{Individu 2} 
  & Colombe & Bigl( frac{g}{2}, frac{g}{2} Bigr)tallstrut & (g,0) 
cline{2-4}
  & Faucon & (0,g)tallstrut & myfrac 
hline
end{tabular}

end{table}
end{document}

Answered by Mico on January 5, 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