6

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?

3
  • 2
    You cannot use vertical lines with booktabs horizontal rules. So you need to either replace \toprule with \hline or get rid of the vertical line. However \toprule is not the correct choice of rule, it should be \midrule but I expect what you're really going for is a thicker line, which demands a different solution tex.stackexchange.com/questions/256731/…
    – Au101
    Aug 26, 2018 at 16:46
  • 2
    In terms of the too wide table cell, there are various solutions, the most basic of which would be to use something like p{2cm} (where 2cm is a fairly arbitrary length, you will have to select the width that you would like to use) instead of a c column. With c the column will be as wide as its contents, and if that means too wide for the page then unfortunately the table will run off the page, the line won't break, because you haven't told it when to break. With p{2cm} you tell it you want a 2cm wide cell and then the line will break to respect that
    – Au101
    Aug 26, 2018 at 16:48
  • 1
    You can use \specialrule{\heavyrulewidth}{0pt}{0pt}: it will have the same thickness as \toprule but no vertical padding. An alternative: load boldline , from the shipunov bundle, which defines horizontal and vertical lines with custom thickness.
    – Bernard
    Aug 26, 2018 at 16:53

4 Answers 4

5

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}
1
  • perfect! thank you :)
    – Vidal
    Aug 27, 2018 at 10:02
13

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

0
7

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
\newlength\mylen
\settowidth\mylen{\sffamily hello hello hello} % measure width of "hello hello hello"
\begin{document}
\begin{center}
\sffamily % switch to sans-serif
\setlength\extrarowheight{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}
0
1

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}>{\raggedright\arraybackslash}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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .