TransWikia.com

How do I create this table?

TeX - LaTeX Asked by Vidal on August 17, 2021

I want to create this table:

Enter image description here

I started with this, but it doesn’t work:

documentclass[11pt,a4paper]{article}
usepackage[latin1]{inputenc}
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
usepackage{graphicx}
usepackage{graphicx}
usepackage{siunitx}
usepackage{booktabs}
begin{document}
begin{center}
    begin{tabular}{c|c}

        hello & hello 

        toprule
        hello hello hello hello hello hello hello hello hello hello space infinity & hello hello hello hello  
        hello hello hello hello hello & hello hello hello hello  

    end{tabular}
   end{center}
   end{document}}

Enter image description here

How can I fix this?

4 Answers

like this:

enter image description here

beside tabularx are used options !{<option>} and Xhline{<width>} from the package array (in this case loaded by the package tabularx) and macro makecell from the package of the same name:

documentclass[11pt,a4paper]{article}
usepackage{makecell, tabularx}

begin{document}
begin{center}
setcellgapes{5pt}makegapedcells
    begin{tabularx}{textwidth}{X!{vline width 1pt} X}
        makecell{hello}   & makecell{hello} 
    Xhline{1pt}
        hello hello hello hello hello hello hello hello hello hello space infinity
                            & hello hello hello hello  
        hello hello hello hello hello hello hello hello hello hello space infinity
                            & hello hello hello hello  
    end{tabularx}
   end{center}
end{document}

Correct answer by Zarko on August 17, 2021

Don't use booktabs with vertical rules.

And don't load packages twice (you have two usepackage{graphicx}).

I have used tabularx, and [4pt] and rule{0pt}{16pt} to add some space before and after the horizontal rule.

documentclass[11pt,a4paper]{article}
usepackage[latin1]{inputenc}
usepackage{tabularx}
begin{document}
begin{center}
    begin{tabularx}{textwidth}{X|X}
        multicolumn{1}{c|}{hello} & 
        multicolumn{1}{c}{hello} [4pt]
        hline
        rule{0pt}{16pt}hello hello hello hello hello hello hello hello hello hello space infinity & hello hello hello hello  
        hello hello hello hello hello & hello hello hello hello  
    end{tabularx}
   end{center}
   end{document}

enter image description here

Answered by CarLaTeX on August 17, 2021

The screenshot that accompanies your query creates the impression that each table column should be just wide enough (but no wider) to typeset three instances of the word "hello", separated by whitespace. If this impression is correct, you should use the p column type for both columns. The p column type takes an argument -- the usable width. In the preamble, be sure to set up a length parameter and measure the width of "hello hello hello" via a settowidth directive.

Oh, and don't use the booktabs package (and midrule directives) if you employ vertical lines. Instead, use hline.

enter image description here

documentclass[11pt,a4paper]{article}
usepackage{array} % for "extrarowheight" macro
newlengthmylen
settowidthmylen{sffamily hello hello hello} % measure width of "hello hello hello"
begin{document}
begin{center}
sffamily % switch to sans-serif
setlengthextrarowheight{2pt} % for a more open "look"
begin{tabular}{p{mylen}|p{mylen}}
multicolumn{1}{c|}{hello} & 
multicolumn{1}{c}{hello} [2pt]
hline
hello hello hello hello hello hello hello hello hello hello space infinity & hello hello hello hello  
hello hello hello hello hello & hello hello hello hello 
end{tabular}
end{center}
end{document}

Answered by Mico on August 17, 2021

Since the rules are very thick, maybe you want to have the rounded caps as in the picture. It's possible to draw rules with rounded caps with Tikz. With the environment {NiceTabular} of nicematrix, you have PGF/Tikz nodes constructed under the row, columns and cells and it's easy to use them with Tikz to draw whatever rule you want.

documentclass{article}
usepackage{nicematrix,tikz}

begin{document}

setlength{extrarowheight}{2mm}
begin{NiceTabular}{>{raggedleft}p{2.6cm}>{raggedrightarraybackslash}p{2.6cm}}
Block{}{hello} & Block{}{hello} 
hello hello hello hello hello hello hello hello hello hello hello hello 
& hello hello hello hello hello hello hello hello hello hello hello hello 
hello hello hello hello hello hello hello hello hello hello hello hello 
& hello hello hello hello hello hello hello hello hello hello hello hello 
hello hello hello hello hello hello hello hello hello hello hello hello 
& hello hello hello hello hello hello hello hello hello hello hello hello 
CodeAfter
tikz draw [very thick, line cap = round] 
            (1-|2) -- (last-|2)
            (2-|1) -- (2-|3) ;
end{NiceTabular}

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Answered by F. Pantigny on August 17, 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