TransWikia.com

Can't fit long sentence into multi-row and mutli-column table

TeX - LaTeX Asked by marknikky on February 14, 2021

Sorry for asking this question even though asked multiple times. But I can’t seem to do it.
I’m new to LaTeX.

Here is the code and the table currently.

documentclass[11pt, a4paper, notitlepage]{article}
usepackage{array}
usepackage{multirow}

begin{table}[h]
centering
begin{tabular}{|l|c|c|c|c|}
hline
multirow{2}{*}{parbox{8em}{Low and high voltage levels with 20% duty cycle}} & multicolumn{2}{c|}{voltage readings} & multicolumn{2}{l|}{calculated values}  tabularnewline
cline{2-5}
    & DC & RMS & DC & RMS tabularnewline
hline
    &    &     &    & tabularnewline
hline
    &    &     &    & tabularnewline
hline
    &    &     &    & tabularnewline
hline
end{tabular}
end{table}

Current table

As you can see above, the long sentence at the top left can’t fit into cell. I want to make this table like this.

Tabel I want

I appreciate any help. Thanks!

2 Answers

With use of makecell for adding vertical spaces around cells' contents and reducing lines spread in the first columns by use of linespread{0.6}selectfont:

enter image description here

Writing values in cells I left to you.
documentclass[11pt, a4paper, notitlepage]{article}
usepackage{array, makecell, multirow}
usepackage{siunitx}

begin{document}
    begin{table}[ht]
    centering
setlengthtabcolsep{3pt}
setcellgapes{3pt}
makegapedcells
renewcommandmultirowsetup{centering} % <---
begin{tabular}{|>{linespread{0.6}selectfont}p{8em}|c|c|c|c|}
hline
multirow{2}{=}{Low and high voltage levels with SI{20}{%} duty cycle} 
    & multicolumn{2}{c|}{voltage readings} 
            & multicolumn{2}{l|}{calculated values}  tabularnewline
cline{2-5}
    & DC    & RMS & DC & RMS    tabularnewline
hline
    &       &     &    &        tabularnewline
hline
    &       &     &    &        tabularnewline
hline
    &       &     &    &        tabularnewline
hline
end{tabular}
    end{table}
end{document}

Correct answer by Zarko on February 14, 2021

You can solve your probem with cellspace, which enables you to defines 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[11pt, a4paper, notitlepage]{article}
usepackage{array}
usepackage{multirow}%
usepackage{cellspace}
setlength{cellspacetoplimit}{8pt}
setlength{cellspacebottomlimit}{8pt}

begin{document}

begin{table}[h]

centering
begin{tabular}{| >{centeringarraybackslash}m{8em}|Sc|Sc|Sc|Sc|}
hline
multirow{1.8}{=}{centering Low and high voltage levels with 20% duty cycle} & multicolumn{2}{Sc|}{voltage readings} & multicolumn{2}{Sl|}{calculated values} tabularnewline
cline{2-5}
    & DC & RMS & DC & RMS tabularnewline
hline
    & & & & tabularnewline
hline
    & & & & tabularnewline
hline
    & & & & tabularnewline
hline
end{tabular}
end{table}

end{document}

enter image description here

Answered by Bernard 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