TransWikia.com

Expansion of box in tabularx

TeX - LaTeX Asked on August 12, 2021

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]{>{RaggedRighthspace{0pt}}m{#1}}


usepackage{siunitx} %  comprehensive (SI) units package



begin{document}



begin{table}[ht]
small % is it necessary?
newlengthcolwidth 
settowidthcolwidth{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}

3 Answers

I would reorganize several aspects of the tabularx material. They are, in no particular order:

  • Give the table a more open and inviting "look" by omitting all vertical lines and by using fewer, but well-spaced, horizontal lines.

  • Center the material in the 6 data columns

  • Permit hyphenation in the first column, even in the first word of each cell

  • Center the cell contents vertically via a suitable redefinition of tabularxcolumn

  • Drop the bolding -- unless you want to be perceived as liking to shout at your readers... -- and, instead, provide more visual structure in the header part of the table with the use of judiciously-placed cmidrule directives.

enter image description here

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]{>{RaggedRighthspace{0pt}}m{#1}}

begin{document}
begin{table}[ht]
small % is it necessary?
newlengthcolwidth 
settowidthcolwidth{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}

Correct answer by Mico on August 12, 2021

Like this?

enter image description here

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}{>{smallraggedrightarraybackslash}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}

However, I would write your table as follows (considering added information in edited question):

documentclass[a4paper, 11pt]{article}
usepackage[margin=3cm]{geometry}
usepackage{booktabs, makecell, tabularx} 
renewcommandthead{smallbfseries}
newcolumntype{Y}{>{raggedrightarraybackslash}X}
newcommandmcc[1]{multicolumn{1}{c}{#1}}

begin{document}

begin{table}[ht]
small
renewcommand{tabularxcolumn}[1]{m{#1}}
setlengthtabcolsep{4pt}
    begin{tabularx}{textwidth}{@{} >{smallbfserieshsize=1.24hsize}Y
                                               *{6}{>{hsize=0.96hsize}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}

enter image description here

Answered by Zarko on August 12, 2021

I sugest the following variant, similar to Mico's answer, in which I placed the repeated dates in a multicolumn below the table. Depending on the actual contents of the cells, this could help save some space and could avoid linebreaks in the first column.

enter image description here

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}

Answered by leandriis on August 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP