2

Below is the way I have the formatting done:

\begin{table}[htbp]
\centering
\begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|}
\hline 
\multicolumn{1}{|c|}{\textit{\textbf{Parameters}}} & 
\multicolumn{1}{c|}{\textit{\textbf{Test (WOE)}}} &
\multicolumn{1}{c|}{\textit{\textbf{Test (WRE)}}} &
\multicolumn{1}{c|}{\textit{\textbf{G}}} &
\multicolumn{1}{c|}{\textit{\textbf{B}}} &
\multicolumn{1}{c|}{\textit{\textbf{W}}} 
\tabularnewline \hline
0.05\_0.025\_0.05\_0.2 & 24.86 & 37.67 &  &  & 
\tabularnewline \hline
0.05\_0.05\_0.05\_0.1 & 36.15 & 52.53 &  &  & 
\tabularnewline \hline
0.05\_0.075\_0.05\_0.2 & 24.23 & 35.30 &  &  & 
\tabularnewline \hline
0.1\_0.05\_0.2\_0.2 & 15.58 & 41.2 &  &  & 
\tabularnewline \hline
0.2\_0.05\_0.05\_0 & 18.78 & 52.98 &  &  & 
\tabularnewline \hline
0.2\_0.05\_0.1\_0.05 & 22.91 & 54.06 &  &  &
\tabularnewline \hline
\end{tabularx}
\caption{To add}
\label{table:to add}   
\end{table}

Seems like the centering isn't making the code work

the way the table looks as of now is as in the attached pictureenter image description here

any advice would be much appriciated

3
  • Welcome to TeX.SX! Could you add some additional information to your question? Do you explicitly want all columns to be equally wide? Do you need linebreaks inside of your table cells? If that's not the case, a simple \begin{tabular}{|l|c|c|c|c|c|c|c|} should already be sufficient.
    – leandriis
    Nov 15, 2020 at 14:56
  • 1
    Also, will your table contain more columns than you currently filled in? You define a total of 8 columns, but only seem to need 6 of them. Please clarify.
    – leandriis
    Nov 15, 2020 at 14:57
  • thanks, Leandriis, it is now solved. only from 2nd to last column i wanted them to be almost of the same length so that the table does not cross the limit of the column on the latext sheet. but now everything is solved. thanks for your help:) Nov 15, 2020 at 17:51

2 Answers 2

3

I assume the reason you wish to employ a tabularx environment is to ensure that the five data columns all have the exact same width.

I suggest you define a centered version of the X column type and remove the \multicolumn wrappers, which are preventing otherwise-sensible line breaks.

enter image description here

\documentclass{article} 
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X'

\begin{document} 
\begin{table}[htbp]
%\centering %% redundant
\begin{tabularx}{\linewidth}{ |l| *{5}{C|} }
\hline 
\textit{\textbf{Parameters}} & 
\textit{\textbf{Test (WOE)}} &
\textit{\textbf{Test (WRE)}} &
\textit{\textbf{G}} &
\textit{\textbf{B}} &
\textit{\textbf{W}} \\ 
\hline
0.05\_0.025\_0.05\_0.2 & 24.86 & 37.67 &  &  & \\ 
\hline
0.05\_0.05\_0.05\_0.1  & 36.15 & 52.53 &  &  & \\ 
\hline
0.05\_0.075\_0.05\_0.2 & 24.23 & 35.30 &  &  & \\ 
\hline
0.1\_0.05\_0.2\_0.2    & 15.58 & 41.2\phantom{0} &  &  & \\ 
\hline
0.2\_0.05\_0.05\_0     & 18.78 & 52.98 &  &  & \\ 
\hline
0.2\_0.05\_0.1\_0.05   & 22.91 & 54.06 &  &  &\\
\hline
\end{tabularx}
\caption{To add}
\label{table:to add}   
\end{table}

\end{document}
1
  • Works like magic. thank you so very much Nov 15, 2020 at 17:47
3

Assuming that in all columns except first are decimal numbers with two integer and two decimal digits. In such a case they the following combination of siunitx and siunitx package can be handy. For column headers are defined two new commands: \mcx and \mr as shortness for \multirow{2}{*}{ ... } (used in column heares where the cells span two line text):

\documentclass{article}
\usepackage{multirow, tabularx}
\newcommand\mcx[1]{\multicolumn{1}{>{\itshape\bfseries%
                                     \centering\arraybackslash}X|}{#1}}
\newcommand\mr[1]{\multirow{2}{*}{{#1}}}
\usepackage{siunitx}

\begin{document}
    \begin{table}[htb]
\begin{tabularx}{\linewidth}{ |l| *{5}{S[table-format=2.2]|} }
    \hline
\mr{\textit{\textbf{Parameters}}} 
    &   \mcx{Test (WOE)}
        &   \mcx{Test (WRE)}
            &   \mcx{\mr{G}}
                &   \mcx{\mr{B}}
                    &   \mcx{\mr{W}}           \\
    \hline
0.05\_0.025\_0.05\_0.2 & 24.86 & 37.67 &  &  & \\
    \hline
0.05\_0.05\_0.05\_0.1  & 36.15 & 52.53 &  &  & \\
    \hline
0.05\_0.075\_0.05\_0.2 & 24.23 & 35.30 &  &  & \\
    \hline
0.1\_0.05\_0.2\_0.2    & 15.58 & 41.2  &  &  & \\
    \hline
0.2\_0.05\_0.05\_0     & 18.78 & 52.98 &  &  & \\
    \hline
0.2\_0.05\_0.1\_0.05   & 22.91 & 54.06 &  &  &\\
    \hline
\end{tabularx}
\caption{To add (table captions are usually at top of tables)}
\label{table:to add}
    \end{table}
\end{document}

enter image description here

1
  • Thank you so very much @Zarko, for your response Nov 15, 2020 at 17:48

You must log in to answer this question.

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