1

I'm to make the following table but it exceed the page from both sides and I can't fix it ... any idea what could be wrong? Thank you

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs, multirow}
\usepackage{multirow}
\usepackage[center, labelfont=bf]{caption}
\begin{table}[h]
\makebox[\textwidth][c]{
\begin{tabular}{c|c|c|c|c|c|c|p{0.4\linewidth}}
\toprule[1.5pt]
& \textbf{Words} & \textbf{En words} & \textbf{Gr words} & \textbf{Al words} & \textbf{\% En words} & \textbf{\% Gr words} &\textbf{\% Al words}\\
\hline
\textbf{Gr/En Mixes} & 3663 & 2207 & 1456 & kati & 60,3 & 39,7 & kati\\
\hline
\textbf{Gr/Al/En/ Mixes} & 131 & 48 & 51 & 32 & 36,6 & 38,9 & 24,4\\
\hline
\textbf{Gr/Al Mixes} & 35 & kati & 24 & 11 & kati & 68,6 & 31,4\\
\hline
\textbf{Al/En Mixes} & 131 & 72 & kati & 59 & 55,0 & kati & 45,0\\
\hline
\textbf{Total mixes} & 3960 & 2327 & 1531 & 102 & 58,8 & 38,7 & 2,6\\
\bottomrule[1.5pt]
\end{tabular}}
\caption{Table 6: The percentage of words in each set of code mixed sentences.}
\end{table}\
6
  • Don't use p{0.4\linewidth} for the last column; why should you?
    – egreg
    Dec 7, 2013 at 16:17
  • how should I make it?
    – Stefanos
    Dec 7, 2013 at 19:58
  • Can you add a screenshot? How much does it exceed the margins? Maybe you could reduce the white space between columns.
    – remus
    Dec 7, 2013 at 19:59
  • how can we add a screenshot here ?
    – Stefanos
    Dec 7, 2013 at 20:04
  • I'll compile your code. You could put the screenshot on some server (imgur) and paste a link. But I'll copy/paste the code you gave.
    – remus
    Dec 7, 2013 at 20:06

1 Answer 1

2

There's a nice feature in tabularx - you can specify the width of the table. Check the below example (I had to enlarge the first column because the text was overlapping with the second column - so it has a different column descriptor: >{\arraybackslash\advance\hsize3em}X:

\begin{table}[h]
\begin{tabularx}{\textwidth}{>{\arraybackslash\advance\hsize3em}X|X|X|X|X|X|X|X}
\toprule[1.5pt]
& \textbf{Words} & \textbf{En words} & \textbf{Gr words} & \textbf{Al words} & \textbf{\% En words} & \textbf{\% Gr words} &\textbf{\% Al words}\\
\hline
\textbf{Gr/En Mixes} & 3663 & 2207 & 1456 & kati & 60,3 & 39,7 & kati\\
\hline
\textbf{Gr/Al/En Mixes} & 131 & 48 & 51 & 32 & 36,6 & 38,9 & 24,4\\
\hline
\textbf{Gr/Al Mixes} & 35 & kati & 24 & 11 & kati & 68,6 & 31,4\\
\hline
\textbf{Al/En Mixes} & 131 & 72 & kati & 59 & 55,0 & kati & 45,0\\
\hline
\textbf{Total mixes} & 3960 & 2327 & 1531 & 102 & 58,8 & 38,7 & 2,6\\
\bottomrule[1.5pt]
\end{tabularx}
\caption{Table 6: The percentage of words in each set of code mixed sentences.}
\end{table}
5
  • nice one!! It's perfect now!!1 Thank you very much! so what was I doing wrong ?
    – Stefanos
    Dec 7, 2013 at 20:31
  • 1
    When you use column descriptor c the column expands such that the text fits on a single line. If you have many columns with a lot of text, eventually, the table will exceed the margins. If you use tabularx with \textwidth as the table width and X as column descriptor then all columns will have a fixed width (equal to each other) and the cell text will possibly be split on multiple lines.
    – remus
    Dec 7, 2013 at 20:35
  • Since you're using the booktabs package, you may also want to consider (i) getting rid of all vertical rules, (ii) replacing the first \hline with \midrule, and (iii) getting rid of all other hline instructions. Trust me, all those rules won't be missed. :-)
    – Mico
    Dec 7, 2013 at 20:40
  • Thanks a lot for your answers..!!! I also applied the tabularx package to a next table and here's what I get [IMG]i.imgur.com/zknKgqt.png?1[/IMG] Why isn't it working this time ?
    – Stefanos
    Dec 7, 2013 at 20:47
  • Enlarge the columns that don't fit like in the example (where I enlarged only the first column).
    – remus
    Dec 7, 2013 at 20:50

You must log in to answer this question.

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