Espansione del box in tabularx

Oct 03 2020
\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}

Risposte

4 Mico Oct 03 2020 at 16:26

Riorganizzerei diversi aspetti del tabularxmateriale. Non sono in un ordine particolare:

  • Dare al tavolo un "aspetto" più aperto e invitante omettendo tutte le linee verticali e utilizzando meno linee orizzontali ma ben distanziate.

  • Centra il materiale nelle 6 colonne di dati

  • Consenti la sillabazione nella prima colonna, anche nella prima parola di ogni cella

  • Centrare il contenuto della cella verticalmente tramite una ridefinizione adeguata di\tabularxcolumn

  • Lascia perdere il grassetto - a meno che tu non voglia essere percepito come una persona che ama gridare ai tuoi lettori ... - e, invece, fornire una struttura più visiva nella parte di intestazione della tabella con l'uso di \cmidruledirettive posizionate in modo giudizioso .

\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}
3 leandriis Oct 03 2020 at 16:42

Suggerisco la seguente variante, simile alla risposta di Mico , in cui ho messo le date ripetute in una multicolonna sotto la tabella. A seconda del contenuto effettivo delle celle, questo potrebbe aiutare a risparmiare spazio ed evitare interruzioni di riga nella prima colonna.

\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 Zarko Oct 03 2020 at 15:42

Come questo?

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

Tuttavia, scriverei la tua tabella come segue (considerando le informazioni aggiunte nella domanda modificata):

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