tabularx 中 box 的扩展

tabularx 中 box 的扩展
\documentclass[a4paper,11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{booktabs} % for well-spaced horizontal lines
\usepackage{tabularx} % for 'tabularx' environment
\usepackage{ragged2e} % for \Centering and \RaggedRight macros
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}


\usepackage{siunitx} %  comprehensive (SI) units package



\begin{document}



\begin{table}[ht]
\small % is it necessary?
\newlength\colwidth 
\settowidth\colwidth{plates (USP)} % set width of 1st col.

\begin{tabularx}{\textwidth}{@{} P{\colwidth} *{6}{C} @{}}
    \toprule
    Key figures
    & \multicolumn{3}{c}{Toluene} 
    & \multicolumn{3}{c}{Nicotinamide}\\

    \cmidrule(lr){2-4} \cmidrule(lr){5-7} 
    & 1st run  & 2nd run  & $\overline{x}~\pm~c_{\overline{x}}$ 
    & 1st run  & 2nd run & $\overline{x}~\pm~c_{\overline{x}}$\\

    \midrule
Capacity factor
    & $\num{1.78e-3}$ & $\num{5.35e-3}$ & $\num{3e-3} \pm \num{2.3e-2}$ & $\num{7.08e-1}$ & $\num{7.01e-1}$ & $\num{7.0e-1} \pm \num{4e-2}$ \\
    \bottomrule
    [0.5mm]
     \multicolumn{7}{l}{\small 1st run: 28.09.2020; 2nd run: 01.10.2020;  $\overline{x}$: average;  $c_{\overline{x}}$: $95\%$ confidence interval }
    \end{tabularx}
    \caption{Computed Descriptors}
    \label{tab:descriptors}
\end{table}
\end{document}

\end{document}

答案1

我将重新整理材料的几个方面tabularx。它们如下(无特定顺序):

  • 通过省略所有垂直线并使用更少但间距适当的水平线,使表格呈现出更加开放和吸引人的“外观”。

  • 将材料置于 6 个数据列的中心

  • 允许在第一列中使用连字符,即使在每个单元格的第一个单词中也是如此

  • 将单元格内容居中垂直通过适当的重新定义\tabularxcolumn

  • 放下加粗——除非你想让人觉得你喜欢您的读者...——而是使用合理放置的\cmidrule指令在表格的标题部分提供更多的视觉结构。

在此处输入图片描述

\documentclass[a4paper,11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{booktabs} % for well-spaced horizontal lines
\usepackage{tabularx} % for 'tabularx' environment
\usepackage{ragged2e} % for \Centering and \RaggedRight macros
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}

\begin{document}
\begin{table}[ht]
\small % is it necessary?
\newlength\colwidth 
\settowidth\colwidth{plates (USP)} % set width of 1st col.

\begin{tabularx}{\textwidth}{@{} P{\colwidth} *{6}{C} @{}}
    \toprule
    Key figures
    & \multicolumn{2}{c}{Toluene} 
    & \multicolumn{2}{c}{Nicotinamide}
    & \multicolumn{2}{c@{}}{Adenine} \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
    & 1st run 28.09.2020 & 2nd run 01.10.2020 
    & 1st run 28.09.2020 & 2nd run 01.10.2020 
    & 1st run 28.09.2020 & 2nd run 01.10.2020 \\
    \midrule
    Retention time & 1&2&3&4&5&6\\
    Peak area  & 1&2&3&4&5&6\\
    Theoretical plates (USP) & 1&2&3&4&5&6\\
    Asymmetry & 1&2&3&4&5&6\\ 
    Resolution & 1&2&3&4&5&6\\
    \bottomrule
    \end{tabularx}
    \caption{Computed Descriptors}
    \label{tab:descriptors}
\end{table}
\end{document}

答案2

我建议使用以下变体,类似于Mico 的回答,其中我将重复的日期放在表格下方的多列中。根据单元格的实际内容,这可以帮助节省一些空间,并可以避免第一列的换行。

在此处输入图片描述

\documentclass[a4paper, 11pt]{article}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}

\usepackage{caption} 
\usepackage{tabularx} 
\usepackage{booktabs}

\begin{document}
\begin{table}[ht]
\caption{Computed Descriptors}
\label{key}
    \begin{tabularx}{\textwidth}{Xcccccc}
        \toprule
        Key figures 
          & \multicolumn{2}{c}{Toluene} 
            & \multicolumn{2}{c}{Nicotinamide} 
              & \multicolumn{2}{c}{Adenine}\\
        \cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
          & 1st run  & 2nd run  & 1st run  & 2nd run  & 1st run  & 2nd run  \\
        \midrule
        Retention time & 1&2&3&4&5&5\\
        Peak area  \\ 
        Theoretical plates (USP)  \\
        Assymetry \\
        Resolution \\
        \bottomrule
        \multicolumn{7}{l}{\small 1st run: 28.09.2020, 2nd run: 01.10.2020}
    \end{tabularx}

\end{table}


\end{document}

答案3

像这样?

在此处输入图片描述

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{pdfpages} % inclusion of external multi-page PDF documents
\usepackage{tabularx} % Tabulars with adjustable-width columns
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}

\begin{document}

\begin{table}[ht]
    \begin{tabularx}{\textwidth}{|Y||Y|Y|Y|Y|Y|Y|}
        \hline
\textbf{Key figures} 
    &   \multicolumn{2}{c|}{\textbf{Toluene}}
            &   \multicolumn{2}{c|}{\textbf{Nicotinamide}}  
                    &   \multicolumn{2}{c|}{\textbf{Adenine}}\\
        \hline
        \hline
\textbf{Retention time} 
    & 1 & 2 & 3 & 4 & 5 & 6\\
        \hline
    \end{tabularx}
    \caption{Computed Descriptors}
\end{table}

\end{document}

不过,我会按如下方式写您的表格(考虑到编辑问题中添加的信息):

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{booktabs, makecell, tabularx} 
\renewcommand\thead{\small\bfseries}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{table}[ht]
\small
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\setlength\tabcolsep{4pt}
    \begin{tabularx}{\textwidth}{@{} >{\small\bfseries\hsize=1.24\hsize}Y
                                               *{6}{>{\hsize=0.96\hsize}Y} @{}}
        \toprule
Key figures
    &   \multicolumn{2}{c}{\thead{Toluene}}
            &   \multicolumn{2}{c}{\thead{Nicotinamide}}
                    &   \multicolumn{2}{c}{\thead{Adenine}}                 \\
    \cmidrule(l){2-3}
    \cmidrule(l){4-5}
    \cmidrule(l){6-7}
Retention time
        & 1st run (28.09.2020) & 2nd run (01.10.2020) & 1st run (28.09.2020) & 2nd run (01.10.2020) & 1st run (28.09.2020) & 2nd run (01.10.2020) \\
 %    & \mcc{1}   & \mcc{2}   & \mcc{3}   & \mcc{4}   & \mcc{5}   & \mcc{6}   \\
    \midrule
Peak area
    & text      & text text & text text & text text & text text & text text \\
Theoretical plates (USP)
    & text      & text text & text text & text text & text text & text text \\
Asymmetry
    & text      & text text & text text & text text & text text & text text \\
Resolution
    & text      & text text & text text & text text & text text & text text \\
    \bottomrule
    \end{tabularx}
    \caption{Computed Descriptors}
\end{table}

\end{document}

在此处输入图片描述

相关内容