Können wir \makecell in Tabularx verwenden?

Können wir \makecell in Tabularx verwenden?

Ich bin nicht sicher, warum ich \makecell nicht verwenden kann. Im Grunde möchte ich dort nur ein Inhaltscenter haben. Das macht mir das Leben sehr schwer.

Bildbeschreibung hier eingeben

\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}

Antwort1

Soweit ich Ihre Frage verstehe, brauchen Sie makecellin mehrzeiligen Zellen keine. Definieren Sie sie einfach neu. Außerdem würde ich für Spaltenüberschriften \theadstattdessen Folgendes verwenden \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}

Bildbeschreibung hier eingeben

Nachtrag: Sie möchten vielleicht gleichmäßigere Spaltenbreiten und Zahlen mit Dezimalstellen. In einem solchen Fall erhalten Sie durch die Verwendung eines SSpaltenspezifizierers (im siunitxPaket definiert) und einer breiteren zweiten Spalte das, wonach Sie suchen:

Bildbeschreibung hier eingeben

\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}

verwandte Informationen