2

I am not sure why my second row of sentences go to my first row.

I need to create a table (without colour) as below:

enter image description here

My MWE:

\documentclass[12pt,oneside]{book}  % Remove draft option to show figures (for final draft), otherwise keep for faster production



\usepackage{tabularx,seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e}       % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{makecell,siunitx} %for table spacing to second row


\usepackage{threeparttable} %to add footnote below table
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{lipsum} % for filler text


\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\usepackage{tabulary,siunitx} 

\renewcommand\theadgape{}


\usepackage{graphicx}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc, positioning,matrix,fit,calc, arrows.meta,
                backgrounds,
                chains}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}              

\begin{document}

\begin{table}[!ht]
\begin{tablenotes}
\centering
\small
\item Hypothesis Test Summary
\end{tablenotes}
\centering
 \begin{tabular}{llrl}
    \toprule
     \small {\textbf{Null Hypothesis}}
     & \small {\textbf{Test}} & \small {\textbf{Sig.}}
     & \small {\textbf{Decision}}\\
     \midrule
    The distribution of Classification \\
    Accuracy is the same across \\ 
    categories of Methods \\
    (1: KL; 2: FC; 3: SD) & 
    Independent \\ Samples \\ Kruskal-Wallis \\ Test  & 
    .000 & 
    Reject the \\ null\\ hypothesis \\
    \bottomrule
    \end{tabular}
\begin{tablenotes}
\small
\item Asymptotic significances are displayed. The significance level is .05.
\end{tablenotes}
\end{table}


\end{document}

Suggested below

enter image description here

\documentclass[12pt,oneside]{book}  % Remove draft option to show figures (for final draft), otherwise keep for faster production



\usepackage{tabularx,seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e}       % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{makecell,siunitx} %for table spacing to second row


\usepackage{threeparttable} %to add footnote below table
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{lipsum} % for filler text


\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\usepackage{tabulary,siunitx} 

\renewcommand\theadgape{}


\usepackage{graphicx}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc, positioning,matrix,fit,calc, arrows.meta,
                backgrounds,
                chains}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}              

\begin{document}

\begin{table}[!ht]
\begin{tablenotes}
\centering
\small
\item Hypothesis Test Summary
\end{tablenotes}
\centering
 \begin{tabular}{llrl}


\begin{tabular}{llrl} 

\toprule \small {\textbf{Null Hypothesis}} & \small {\textbf{Test}} & \small {\textbf{Sig.}} & \small {\textbf{Decision}}\\ 

\midrule 

\begin{tabular}{l}The distribution of Classification \\ Accuracy is the same across \\ categories of Methods \\ (1: KL; 2: FC; 3: SD) \end{tabular}

&

\begin{tabular}{l} Independent \\ Samples \\ Kruskal-Wallis \\ Test \end{tabular} 

& .000 
& 
\begin{tabular}{l} Reject the \\ null\\ hypothesis
\end{tabular} \\ 

\bottomrule 
\end{tabular}



    \end{tabular}
\begin{tablenotes}
\small
\item Asymptotic significances are displayed. The significance level is .05.
\end{tablenotes}
\end{table}







\end{document}
  • You can use tabular in tabular (this approach is close to your code) ... The way you have it, you break the line of the whole (outer) tabular... If you want line-breaks inside the cell ... place the whole cell in a {l} tabular ... and break there the lines of the inner tabular – koleygr Oct 2 '19 at 14:53
  • @koleygr Could you give me an example, please? Could not understand the meaning of {1} in tabular. – aan Oct 2 '19 at 14:55
  • \begin{tabular}{llrl} \toprule \small {\textbf{Null Hypothesis}} & \small {\textbf{Test}} & \small {\textbf{Sig.}} & \small {\textbf{Decision}}\\ \midrule \begin{tabular}{l}The distribution of Classification \\ Accuracy is the same across \\ categories of Methods \\ (1: KL; 2: FC; 3: SD) \end{tabular}&\begin{tabular}{l} Independent \\ Samples \\ Kruskal-Wallis \\ Test \end{tabular} & .000 & \begin{tabular}{l} Reject the \\ null\\ hypothesis\end{tabular} \\ \bottomrule \end{tabular} – koleygr Oct 2 '19 at 15:03
  • 1
    @koleygr thanks. It works. However, I am not sure why there is an indent gap between the first row and the second row. I posted the picture above. – aan Oct 2 '19 at 15:12
4

Here's another tabularx-based solution. It uses the L column type for three of the four columns, while making it easy to specify unequal (relative) column widths. The only rule you need to keep in mind is that the sum of the relative column widths (here: 1.5+0.75+0.75=3) must be the same as the number of columns of type L. In the following solution, the first column is set to be twice as wide as columns 2 and 4.

enter image description here

\documentclass[12pt,oneside]{book} 
\usepackage{tabularx,ragged2e,caption,booktabs} 
\captionsetup{skip=0.333\baselineskip}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash\hsize=#1\hsize}X}
\begin{document}

\begin{table}
\setlength\tabcolsep{4pt} % default: 6pt
\caption*{Hypothesis Test Summary}
\begin{tabularx}{\textwidth}{@{}L{1.5}L{0.75}lL{0.75}@{}}
\toprule
\textbf{Null Hypothesis} & \textbf{Test} & \textbf{Sign.} & \textbf{Decision}\\
\midrule
The distribution of Classification Accuracy is the same across categories of methods (1:~KL; 2:~FC; 3:~SD) & 
Independent-Samples Kruskal-Wallis Test  & 
0.000 & 
Reject the null hypothesis \\
\bottomrule
\end{tabularx}

\smallskip\footnotesize
Asymptotic significance levels are displayed. The significance level is~.05.
\end{table}
\end{document}
  • thanks. it works well. If I want the word being break nicely, for example Classifica- to Classification. rather than break the word – aan Oct 2 '19 at 16:43
  • 1
    @aan - I'm afraid I don't understand what you mean by "If I want the word being break nicely, for example Classifica- to Classification". Do you maybe mean to say that you want to suppress hyphenation? If so, just change \RaggedRight to \raggedright in the definition of the L column type. Do be aware that if you suppress hyphenation, you'll be an extremely ragged looking right-hand edge of the text block. – Mico Oct 2 '19 at 16:59
3

I would use tabularx table environment and left line braking to the L column tape defined as \newcolumntype{L}{>{\RaggedRight}X}. For vertical centering of cells' contents I suggest to redefining X column type: \renewcommand\tabularxcolumn[1]{m{#1}}:

\documentclass[12pt, oneside]{book} 

\usepackage{caption}
\usepackage{booktabs, makecell, tabularx, threeparttable} 
\renewcommand\theadfont{\small\bfseries}  
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage{ragged2e}

\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows.meta,
                backgrounds,
                calc, chains,
                decorations.pathreplacing,
                fit,
                matrix,
                positioning,
                }

\begin{document}

\begin{table}[!ht]
\centering
\small
\renewcommand\tabularxcolumn[1]{m{#1}}
 \begin{tabularx}{\linewidth}{@{} >{\hsize=1.35\hsize}LL S[table-format=1.2] 
                                  >{\hsize=0.65\hsize}L @{}}
    \toprule
\thead{Null Hypothesis} & \thead{Test}  & {\thead{Sig.}}  & \thead{Decision}            \\
    \midrule
The distribution of Classification Accuracy is the same across categories of Methods (1: KL; 2: FC; 3: SD)
                        & Independent Samples Kruskal-Wallis Test
                                        & 0.00         & Reject the null hypothesis    \\
    \bottomrule
\end{tabularx}
\begin{tablenotes}\small
\item   Asymptotic significances are displayed. The significance level is .05.
\end{tablenotes}
    \end{table}
\end{document}

enter image description here

addendum: if you not like to have hyphenate words, that replace \newcolumntype{L}{>{\RaggedRight}X} with \newcolumntype{L}{>{\raggedright\arraybackslash}X}. After than you will obtain the following result:

enter image description here

  • thanks. it works well. If I want the word being break nicely, for example Classifi- to Classification. rather than break the word – aan Oct 2 '19 at 16:17
  • 2
    @aan, if you not like to have hyphenate words in table, than you need to change definiton of column type L. See addendum in my answer. – Zarko Oct 2 '19 at 16:53
2

Here it the completed way of my comment (sorry for the gap -fixed here-)

\documentclass[12pt,oneside]{book}  % Remove draft option to show figures (for final draft), otherwise keep for faster production



\usepackage{tabularx,seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e}       % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{makecell,siunitx} %for table spacing to second row


\usepackage{threeparttable} %to add footnote below table
\renewcommand{\TPTtagStyle}{\itshape} % optional
\usepackage{lipsum} % for filler text


\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\usepackage{tabulary,siunitx} 

\renewcommand\theadgape{}

\begin{document} 
\begin{tabular}{llrl} \toprule
\small {\textbf{Null Hypothesis}} & \small {\textbf{Test}} & \small {\textbf{Sig.}} & \small {\textbf{Decision}}\\ \midrule \begin{tabular}{@{}l@{}}The distribution of Classification \\ Accuracy is the same across \\ categories of Methods \\ (1: KL; 2: FC; 3: SD) \end{tabular}&
\begin{tabular}{@{}l@{}} Independent \\ Samples \\ Kruskal-Wallis \\ Test \end{tabular} & .000 & 
\begin{tabular}{@{}l@{}} Reject the \\ null\\ hypothesis\end{tabular} \\ \bottomrule \end{tabular}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.