3

I am creating a table like this :

\begin{table}[htbp]
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
    \hline
    aaaaaaaaaaaaaaaaaaa & bbbbbbbbbbbbbbbbb & cccccccccccccccc & ddddddddddddd & eeeeeeeeeeeee & & & & \\
    \hline
     erd & fds & 0 & 1470& MIN & 25th & 50th & 75th & MAX \\
     \hline
\end{tabular}
\end{table}

How can I merge the last few blank cells with 'eee', and if the contents are long, the right part of the table will disappear, how can I adjust it? Many thanks.

enter image description here

4
  • Welcome to TeX SX! One way is to use the tabularx environment, to control the width of the table (this requires using at least one X column). Merging would be done through a\multicolumn{5}{c}{eee}.
    – Bernard
    Commented Aug 10, 2019 at 9:46
  • Hi @Bernard thanks, could you please be more specific by 'control the width of the table (this requires using at least one X column)'? Please see my edit, the width of my table is too big and the right side is disappeared.
    – Cecilia
    Commented Aug 10, 2019 at 10:15
  • For your edit, you can load makecell, which allows for line breaks in standard cells. I would write, for the first cell, something like \makecell{Number of \\ distinct values}. Other than that, you should post a short code, more representative of your real code.
    – Bernard
    Commented Aug 10, 2019 at 10:33
  • @Cecilia, please extend your code fragment to complete small document. We now anything about your document layout. Also please provide real content of one row of table.
    – Zarko
    Commented Aug 10, 2019 at 10:34

2 Answers 2

4
\documentclass{article}
\begin{document}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
    \hline
    aaa & bbb & ccc & ddd & \multicolumn{5}{c|}{eee} \\
    \hline
    erd & fds & 0 & 1470& MIN & 25th & 50th & 75th & MAX \\
    \hline
\end{tabular}

\end{document}

enter image description here

2
  • Hi thanks, please see my edit, the width of my table is too big and the right side is disappeared, is there a way I can adjust it?
    – Cecilia
    Commented Aug 10, 2019 at 10:17
  • use a tabularx with the column specifier X. You'll find a lot of examples here
    – user187802
    Commented Aug 10, 2019 at 10:46
2

You can use

\multicolumn{5}{c}{eee}

which will merge 5 cells.

Related to adjusting the visual appearance of tables in general there are packages such as booktabs that will help you create good looking output.

2
  • 1
    You should show to OP how to use booktabs. this will make more noticeably difference between yours and @user187802 answer.
    – Zarko
    Commented Aug 10, 2019 at 10:09
  • Also note, that with {c} (instead of {c|}, the rightmost vertical line would be missing in the first row.
    – leandriis
    Commented Aug 10, 2019 at 11:28

You must log in to answer this question.

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