0

I am quite new to latex and building a table. I want to split the content into 2 row, so make it more space in a table.

From one row:

Sig. (2-tailed)

into two row:

Sig.
(2-tailed)

enter image description here

\documentclass[12pt,oneside]{book}

\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{hhline, boldline}
\usepackage{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{siunitx} %for table spacing to second row
\usepackage{tabulary}
\usepackage{graphicx}

\begin{document}


\begin{table}[h!]
\centering
    %  \begin{tabularx}{\textwidth}{@{}M*{6}{N}@{}}
\begin{tabularx}{\textwidth}{>{\RaggedRight\arraybackslash}cXccccc}
        \toprule
    & & \multicolumn{2}{>{\centering\arraybackslash}p{8em}}{\textbf{95\% Confidence Interval of the Difference}}  &  \textbf{t}
      & \textbf {df} 
      & \textbf {Sig. (2-tailed)}  \\
     \cmidrule{3-4}  %\cmidrule(lr){3-4}
     & & \multicolumn{1}{c}{\textbf{Lower}} &  \multicolumn{1}{c}{\textbf{Upper}} & & &\\
\midrule
     Pair 1 & \textit{Abcde qpweo example dataset} (AA) - \textit{Abcde qpweo example dataset} (BB) & 52.44\% &  34.42\%  & 1.55 & 4 & 0.001\\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document}
  • Welcome to TeX.SX! Do you also want to vertically center the header of the last line? Please clarify the desired alignment. Please also explain the two blue arrows in your screenshot. Do you also want to vertically center "t" and "df"? If so, with respect to the first three lines of the second column header or to all 4 of them? Please clarify. – leandriis Nov 03 '19 at 14:12
  • To split the text into two lines, I'd suggest to use \makecell or \thead from the makecell package. Various possible vertical alignments of such a two lined header using the before mentioned commands, can also be found in the answers to the following question: https://tex.stackexchange.com/q/510888/134144 – leandriis Nov 03 '19 at 14:17
  • @leandriis. thanks for your first reply. English is not my first language. I will my best. I want vertically centre of the header for "t" and "df". and also making the Sig. (2-tailed) into 2 line. – newlatex Nov 03 '19 at 14:17
  • Is https://i.stack.imgur.com/Xi1yZ.png what you want to achieve? – leandriis Nov 03 '19 at 14:37
  • @leandriis. yes, yes. what method do you use in code (could you share it in answer) and also how do you attached photo in message here? – newlatex Nov 03 '19 at 14:38

3 Answers3

0

@newlatex--all you need to do is ::


    \documentclass[12pt,oneside]{book}

    \usepackage[showframe]{geometry}
    \usepackage{amsmath}
    \usepackage{ragged2e}
    \usepackage{makecell, multirow, tabularx}
    \renewcommand\theadfont{\small\bfseries} % for bold in table using \small
    \renewcommand\theadgape{}
    \usepackage[svgnames, table]{xcolor}
    \usepackage{hhline, boldline}
    \usepackage{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{siunitx} %for table spacing to second row
    \usepackage{tabulary}
    \usepackage{graphicx}

    \begin{document}


    \begin{table}[h!]
    \centering
        %  \begin{tabularx}{\textwidth}{@{}M*{6}{N}@{}}
    \begin{tabularx}{\textwidth}{>{\RaggedRight\arraybackslash}cXccccc}
            \toprule
        & & \multicolumn{2}{>{\centering\arraybackslash}p{8em}}{\textbf{95\% Confidence Interval of the Difference}}  &  \textbf{t} & \textbf {df} & \textbf {Sig. }  \\

         \cmidrule{3-4}  %\cmidrule(lr){3-4}
         & & \multicolumn{1}{c}{\textbf{Lower}} &  \multicolumn{1}{c}{\textbf{Upper}} & \textbf{t}&\textbf {df} &\textbf{(2-tailed)}\\
    \midrule
         Pair 1 & \textit{Abcde qpweo example dataset} (AA) - \textit{Abcde qpweo example dataset} (BB) & 52.44\% &  34.42\%  & 1.55 & 4 & 0.001\\
            \bottomrule
        \end{tabularx}
    \end{table}

    \end{document}

``````````````````````````````````````````

js bibra
  • 21,280
0

With the help of \multirow and \makecell:

enter image description here

\documentclass[12pt,oneside]{book}

\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{hhline, boldline}
\usepackage{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{siunitx} %for table spacing to second row
\usepackage{tabulary}
\usepackage{graphicx}

\begin{document}


\begin{table}[h!]
\centering
    %  \begin{tabularx}{\textwidth}{@{}M*{6}{N}@{}}
\begin{tabularx}{\textwidth}{>{\RaggedRight\arraybackslash}cXccccc}
        \toprule
    & & \multicolumn{2}{>{\centering\arraybackslash}p{8em}}{\textbf{95\% Confidence Interval of the Difference}}  &  \multirow{4.5}{*}{\textbf{t}}
      & \multirow{4.5}{*}{\textbf {df}} 
      & \multirow{4.5}{*}{\makecell{\textbf{Sig.}\\ \textbf{(2-tailed)}}}  \\
     \cmidrule{3-4}  %\cmidrule(lr){3-4}
     & & \multicolumn{1}{c}{\textbf{Lower}} &  \multicolumn{1}{c}{\textbf{Upper}} & & &\\
\midrule
     Pair 1 & \textit{Abcde qpweo example dataset} (AA) - \textit{Abcde qpweo example dataset} (BB) & 52.44\% &  34.42\%  & 1.55 & 4 & 0.001\\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document}
leandriis
  • 62,593
  • thanks. How do you add a picture in comment here? For example you did in i.stack.imgur.com/Xi1yZ.png – newlatex Nov 03 '19 at 16:31
0

I suspect that this is new question follows from how-to-fit-a-table-in-a-one-row. As starting point for the table showed in the first image in mentioned question can be written as follows:

\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx, tabulary}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage{threeparttable} %to add footnote below table
 \usepackage[svgnames, table]{xcolor}
\usepackage[skip=1ex]{caption} %for table spacing to second row
\usepackage{siunitx} %for table spacing to second row

    \begin{document}
        \begin{table}[ht]
\sisetup{round-mode = places,
         round-precision=2,
         detect-weight
         }
\setlength\tabcolsep{3pt}
    \begin{threeparttable}
\caption{Bootstrap for paired Samples Test}
\label{tab:blabla}
        \begin{tabularx}{\linewidth}
                {@{} l L *{3}{S[table-format=2.2,table-space-text-post={\,\%}]}
                              S[table-format=1.3]
                         *{2}{S[table-format=2.2,table-space-text-post={\,\%}]}
                 @{}}
        \toprule
        &   &               &               &               &       & \multicolumn{2}{c}{\thead{\SI{95}{\%} Confidence\\ Interval}}                                    \\
        \cmidrule{7-8}
        &   & {Mean}        & {Bias}        & {\thead{SE\tnote{a}}} & {\thead{STT\tnote{b}}}
                                                                    & {\thead{Lower}}
                                                                        & {\thead{Upper}}   \\
        \toprule
Pair 1  & Testing example dataset (BB) - Testing Example Dataset (AA)
            & 12.34567\%    & 12.34567\%    & 12.34567\%    & 1.234 & 12.34567\%    & 12.34567\%    \cr
        \bottomrule
    \end{tabularx}
\begin{tablenotes}[para, flushleft]
\item[a]    SE: Standard Error
\item[b]    STT: Signal, Two Tailed
\end{tablenotes}
    \end{threeparttable}
        \end{table}
\end{document}

enter image description here

On similar way you can redesign your table from this question:

\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx, tabulary}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage{threeparttable} %to add footnote below table
 \usepackage[svgnames, table]{xcolor}
\usepackage[skip=1ex]{caption} %for table spacing to second row
\usepackage{siunitx} %for table spacing to second row

    \begin{document}
        \begin{table}[ht]
\sisetup{round-mode = places,
         round-precision=2,
         detect-weight
         }
    \begin{threeparttable}
\caption{Bootstrap for paired Samples Test}
\label{tab:blabla}
        \begin{tabularx}{\linewidth}
                {@{} l L *{2}{S[table-format=2.2,table-space-text-post={\,\%}]}
                              S[table-format=1.2]
                              S[table-format=1.0]
                              S[table-format=1.3]
                  @{}}
        \toprule
        &   & \multicolumn{2}{c}{\thead{\SI{95}{\%} CID\tnote{a}}} 
                                    &               &               &                           \\
        \cmidrule{3-4}
        &   & {\thead{Lower}}    
                & {\thead{Upper}}   & {\thead{t}}   & {\thead{df}}  & {\thead{STT\tnote{b}}}   \\
        \toprule
Pair 1  & Testing example dataset (BB) - Testing Example Dataset (AA)
            & 12.34567\%    
                & 12.34567\%        & 1.23          & 4             & 0.001                     \\
        \bottomrule
    \end{tabularx}
\begin{tablenotes}[para, flushleft]
\item[a]    CID: Confidence Interval of the Difference
\item[b]    STT: Signal, Two Tailed
\end{tablenotes}
    \end{threeparttable}
        \end{table}
\end{document}

enter image description here

Zarko
  • 296,517