# [Tex/LaTex] How to center text in tabularx?

horizontal alignmenttabularx

Possible Duplicate:
Centering in tabularx and X columns

I was using \begin{tabular} to insert a table in my article. The titles for columns were long which caused the table to extend out across the paper boundary. I searched online and found that {tabularx} will wrap the text. I used it which solved the problem. But I want my content to be centered. How do I achieve this in the {tabularx} environment? I am new to LaTeX and this is my first article. I have copied my script below:

\begin{table}[ht]
\caption{Clear Zone Deficiency and Crash Severity}
\centering
\begin{tabularx} {\linewidth} {X X X X X X X}
\hline\hline
CLEAR ZONE DEFICIENCY & TOTAL CRASHES & FATAL & INJURY & PDO & \% CRASHES & \% FATAL \\ [0.5ex]
\hline
0ft-4ft & 4 & 0 & 2 & 2 & 7.84 & 0 \\
4ft-8ft & 14 & \textbf{1} & 4 & 9 & 27.45 & 9.09 \\
8ft-12ft & 15 & \textbf{1} & 5 & 9 & 29.41 & 9.09 \\
12ft + & 18 & \textbf{9} & 4 & 5 & 35.29 & \textbf{81.82}\\
\hline
TOTAL & 51 & 11 & 15 & 25 & 100 & 100 \\ [1ex]
\hline
\end{tabularx}
\label{table:CZseverity}
\end{table}

If you use the tabulary instead, and then use C instead of X, it will automatically adjust the table widths and center the contents:

\documentclass{article}

\begin{document}

\begin{table}[ht]
\caption{Clear Zone Deficiency and Crash Severity}
\centering
\begin{tabulary} {\linewidth} {C C C C C C C}
\hline\hline
CLEAR ZONE DEFICIENCY & TOTAL CRASHES & FATAL & INJURY & PDO & \% CRASHES & \% FATAL \\ [0.5ex]
\hline
0ft-4ft & 4 & 0 & 2 & 2 & 7.84 & 0 \\
4ft-8ft & 14 & \textbf{1} & 4 & 9 & 27.45 & 9.09 \\
8ft-12ft & 15 & \textbf{1} & 5 & 9 & 29.41 & 9.09 \\
12ft + & 18 & \textbf{9} & 4 & 5 & 35.29 & \textbf{81.82}\\
\hline
TOTAL & 51 & 11 & 15 & 25 & 100 & 100 \\ [1ex]
\hline
\end{tabulary}
\label{table:CZseverity}
\end{table}

\end{document}

If you find some of your titles have unnecessary broken words and you don't need word wrapping in those columns, just use c instead of C.