I have a table which needs to expand to the width of my page and I do this by
\begin{table}[H]
\centerline{
\begin{tabularx}{\textwidth}{|X|X|}
\hline
\textbf{Number} & \textbf{Probability} \\ \hline
0 & 100 \% \\ \hline
998.13 & 60 \% \\ \hline
1996.26 & 31.37 \% \\ \hline
2994.39 & 16.11 \% \\ \hline
3992.52 & 8.26 \% \\ \hline
4990.64 & 4.23 \% \\ \hline
5988.77 & 2.17\% \\ \hline
6986.90 & 1.11\% \\ \hline
7828.46 & 0.63\% \\ \hline
\end{tabularx}
}
\caption{}
\end{table}
however, the text is not becoming centered in the table , it is left justified. How can I center the text and get the text to be centered? (As I only managed one at a time)
Best Answer
Nice version
Two table variant
Remarks:
The optional parameter of
tabular
ortabularx
specifies, where the anchor of the table lies.t
means the top element of the table (top rule or first row),b
means the bottom line or last row. As default the table is vertically centered.Horizontal placement. First use
\centering
instead of\centerline{...}
.\centering
centers the lines of the paragraph, whereas\centerline
restricts the contents to a\hbox
and does not warn, if the elements do not fit in the current line width. If the two tables fit in one line, then\hfill
inbetween will move the left table to the left and right table to the right side of the text area. The weaker\hfil
can be used, if the free space between the tables should be equally distributed to the left of the left table, the middle between the tables and to the right of the right table.Full example:
Stretched to text width:
With ugly lines
Centering without alignment of numbers