Force Kile to create tables that are inside the page width

I am using the Tabular Wizard on Kile to create a \tabularx environment for one of my tables, and I want it to fit inside a page. Currently this is my setup:

{%
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}
\begin{center}
\begin{tabularx}{\textwidth}[]{l|c|c|c|}\cline{2-4}
%data ....
\end{tabularx}
\end{center}
}%


However, even with \textwidth parameter my tables are going way of the page's limits.

I tried reading this discussion: - How to force a table into page width?

But it didn't help, the solution picked does not seem to work. How can I fix this?

The way tabularx can adjust the width of the table is to change the width of specific columns. The default column types (r, c, l) are not modified by tabularx, so they will not behave any differently. Instead, a new column type X is defined, which allows text to break, and has a width that changes depending on the width of the other columns. See the examples in the manual.

Hence, when using just l and c columns, they will be just as wide as their widest content.

If you want the content of an X column right aligned, use >{\raggedleft\arraybackslash}, for centering replace \raggedleft with \centering. The \arraybackslash is really only necessary in the last column, but below I added it in all of them.

\documentclass[border=2mm]{standalone}
\usepackage{tabularx}
\newcommand\word{a bunch of text and some more text and yet more text}
\begin{document}

\begin{tabularx}{8cm}{
|>{\raggedleft\arraybackslash}X
|>{\centering\arraybackslash}X
|>{\raggedright\arraybackslash}X
| X |}
Right & Center & Left & Justified \\ \hline
\word & \word & \word & \word
\end{tabularx}
\end{document}

• So it means I cannot center my text or adjust it to the right? Is there a way for me to do it and still use something like tabularX? This seems like a huge limitation in latex. Mar 15, 2014 at 21:34
• @Flame_Phoenix Of course you can, just as you can right justify normal text. You just need to add \raggedleft or \centering in a cell, or in the column specification. I'll add a quick example. Mar 15, 2014 at 21:56
• Ah, I get it, this solved some of my problems thanks ! Now I am creating yet another question about yet another issue :D Mar 15, 2014 at 22:16