如何使用 \thead 将一个句子变成两行

如何使用 \thead 将一个句子变成两行

我曾尝试包含\thead但没有效果。

我想Class AA进入Class BB第二线。

在此处输入图片描述

 \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}
\usepackage{graphicx}

\usepackage[font=small,labelfont={bf,sf}, textfont={sf}, justification=centering]{caption}


% \hypersetup{pdfborder = {0 0 0}}

\begin{document}


\begin{table}[h!]
\centering
\sisetup{table-format=6.0, table-number-alignment=center, table-column-width=6.0cm}
 \begin{tabular}{lSS}
     \toprule
     \multirow{2}{*}{} & \multicolumn{2}{c}{\thead{\makebox[0pt]{Sample Number}}}\\ 
     \cmidrule{2-3}
    &{\textbf{\thead{Testing1 species} \thead{(Class AA)}}}
     & {\textbf{Testing2 species (Class BB)}} \\
     \midrule
    High Wavenlength & {18, 17, 15, 18} & {19, 18, 1, 11} \\
    Medium Wavenlength & {18, 17, 18} & {19, 18, 11} \\
    Low Wavenlength & {18, 17, 15, 18} & {19, 18, 1, 11} \\
     \bottomrule
    \end{tabular}
\end{table}


\end{document}

答案1

由于\theadfont已重新定义为包含\bfseries,因此您无需\textbf在命令中使用\thead。要引入换行符,只需在命令\\内部使用即可\thead。在下面的 MWE 中,我还将S类型列替换为常规c类型列。这样,您的表格将很容易适应文本宽度。我还\sisetup从表格中删除了,因为在这个特定的表格中没有与相关的内容siunitx

在此处输入图片描述

\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}
\usepackage{graphicx}

\usepackage[font=small,labelfont={bf,sf}, textfont={sf}, justification=centering]{caption}

\begin{document}


\begin{table}[h!]
\centering
 \begin{tabular}{lcc}
     \toprule
      & \multicolumn{2}{c}{\thead{Sample Number}}\\ 
     \cmidrule{2-3}
     & \thead{Testing1 species \\(Class AA)}
     & \thead{Testing2 species \\ (Class BB)} \\
     \midrule
    High Wavenlength & {18, 17, 15, 18} & {19, 18, 1, 11} \\
    Medium Wavenlength & {18, 17, 18} & {19, 18, 11} \\
    Low Wavenlength & {18, 17, 15, 18} & {19, 18, 1, 11} \\
     \bottomrule
    \end{tabular}
\end{table}


\end{document}

相关内容