我們可以在 Tabularx 中使用 \makecell

我們可以在 Tabularx 中使用 \makecell

我不知道為什麼我不能使用 \makecell 基本上,我只是想在那裡有一個內容中心。讓我的生活變得非常困難。

在此輸入影像描述

\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{threeparttable} %to add footnote below table
\usepackage{tabulary}


\begin{document}

\begin{table}[h!]
\centering
\begin{threeparttable} 
\begin{tabularx}{\textwidth}{>{\RaggedRight\arraybackslash}Xlcccc}  % Changed from c to X, or remove >{} and change to `l`column.
\toprule
    &  & {\textbf{N}} 
    &  {\textbf{Mean Rank}} 
    &  {\makecell{\textbf{Sum of}\\ \textbf{Ranks}}}  
    % & \multicolumn{1}{>{\centering\arraybackslash}p{8em}}{\textbf{BCa 95\% Confidence Interval of the Difference}}  
    \\
\midrule
\multirow{2.5}{*}{\makecell{\textit{AAaaaa Example Dataset}} \\ (AA) - \\ {\textit{AAaaaa Example Dataset}} \\ (BB) }
    & Negative Ranks
    & 55\tnote{a}
    & 2.50
    & 34.00 \\
& Positive Ranks & 0\tnote{b} & 0.00 & 0.00 \\
& Ties & 0\tnote{c} & \\
& Total & 10 \\
    \bottomrule
\end{tabularx}
\footnotesize 
\end{threeparttable}
\end{table}

\end{document}

答案1

據我了解您的問題,您不需要makecell多行單元格。只是重新定義它。另外對於列標題,我會使用\thead而不是\makecel

\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage[svgnames, table]{xcolor}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}

\begin{document}
    \begin{table}[ht]
    \centering
\begin{threeparttable}
\begin{tabularx}{\textwidth}{>{\RaggedRight\let\\ \newline}Xl cc c}  
    \toprule
    &  & \thead[b]{N}   & \thead[b]{Mean\\ Rank}    & \thead[b]{Sum of\\ Ranks}    \\
    \midrule
\multirow{4}{=}{\itshape
                  AAaaaa Example Dataset\\  
                  \normalfont
                  (AA) -\\                 
                  \itshape
                  AAaaaa Example Dataset\\                  
                  \normalfont
                  BB }
    & Negative Ranks    & 55\tnote{a}   & 2.50  & 34.00 \\
    & Positive Ranks    & 0\tnote{b}    & 0.00  & 0.00  \\
    & Ties              & 0\tnote{c}    &       &       \\
    & Total             & 10            &       &       \\
    \bottomrule
\end{tabularx}
\end{threeparttable}
    \end{table}
\end{document}

在此輸入影像描述

附錄: 您可能希望列的寬度和數字在小數點處對齊,間隔更均勻。在這種情況下,使用S列說明符(在siunitx套件中定義)和更寬的第二列可以滿足您的需求:

在此輸入影像描述

\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage[svgnames, table]{xcolor}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
    \centering
    \sisetup{table-column-width=0.1\linewidth,
             table-align-text-post=false, 
             table-format=2.2}
\begin{threeparttable}
\begin{tabularx}{\textwidth}{>{\RaggedRight\let\\ \newline\hsize=1.2\hsize}X
                             >{\hsize=0.8\hsize}X  
                             S[table-format=2.0]SS}  
    \toprule
    &  & {\thead[b]{N}} & {\thead[b]{Mean\\ Rank}}  & {\thead[b]{Sum of\\ Ranks}}    \\
    \midrule
\multirow{4}{=}{\itshape
                  AAaaaa Example Dataset\\  
                  \normalfont
                  (AA) -\\                 
                  \itshape
                  AAaaaa Example Dataset\\                  
                  \normalfont
                  BB }
    & Negative Ranks    & 55\tnote{a}   & 2.50  & 34.00 \\
    & Positive Ranks    & 0\tnote{b}    & 0.00  & 0.00  \\
    & Ties              & 0\tnote{c}    &       &       \\
    & Total             & 10            &       &       \\
    \bottomrule
\end{tabularx}
\end{threeparttable}
    \end{table}
\end{document}

相關內容