TransWikia.com

Table without thin vertical lines in Tabularx (Table in style of ACS Macro Letter journal)

TeX - LaTeX Asked by Benson_G on January 10, 2021

In this Thread (https://tex.stackexchange.com/a/301036/229635) it was explained how to make the small vertical lines between two cells disappear by using tabularx and columncolor and changing the overhang parameters within a multicolumn.

Now I am looking for a way how to create a Table like shown in the picture attached to this post.

The reason why I am asking for your help is that the code updated on August 7th 2020 by Bernard (see link above) doesn’t create a table fitting to the text width of my document.

In other words: Is there a way to get rid of all the absolute values and the multicolumn used in the m{} parameters so that the table fits still the textwidth no matter how many columns the table has while still implementing the overhang parameter for color fill to avoid the thin white lines between the cells?
I Want to create a Table having no gridlines and a light gray head row without the small vertical lines between color filled cells while using cellcolor.

Thanks a lot in advance,
Benson_G

Picture Reference:
Worm, M.; Leibig, D.; Dingels, C.; Frey, H. Cleavable Polyethylene Glycol: 3,4-Epoxy-1-butene as a Comonomer to Establish Degradability at Physiologically Relevant pH.ACS Macro Letters2016,5(12), 1357–1363

enter image description here

documentclass[a4paper,10pt, enabledeprecatedfontcommands]{scrartcl} %Art des Dokuments, Schriftgröße etc.
usepackage[utf8]{inputenc}%Direkte Angabe von Umlauten möglich 
usepackage[left=3cm,right=2cm,top=2cm,bottom=2cm,includehead]{geometry}%Maße für die wissenschaftliche Arbeit
usepackage[parfill]{parskip} %Bessere Seitenumbrüche
usepackage[onehalfspacing]{setspace} %Zeilenabstand
usepackage[T1]{fontenc} %Silbentrennung
usepackage[english]{babel} %Sprachanpassungen
usepackage{graphicx} %Einfügen von Bildern
usepackage{tabularx} %Tabellen
usepackage{booktabs} %Weitere Möglichkeiten für Tabellen
usepackage{here} %Lage von Tabellen und Bildern 
usepackage{units}
usepackage{physics}
usepackage{amsmath}
usepackage{textgreek}
usepackage{textcomp}
usepackage{amssymb}
usepackage[labelformat=simple]{subcaption}
usepackage{float}
usepackage{pdfpages}
usepackage{lmodern} 
usepackage{enumitem}
usepackage[hyphens]{url}  %% be sure to specify the option 'hyphens'
% usepackage[pdftex,bookmarksnumbered,hidelinks,breaklinks]{hyperref}
usepackage[superscript]{cite}
usepackage[scaled]{helvet}
renewcommandfamilydefault{sfdefault} 
usepackage[version=3]{mhchem} %Summenformeln angeben
usepackage[labelsep=period]{caption}
usepackage[per-mode = reciprocal, output-decimal-marker={,}, exponent-product = {cdot}]{siunitx} %Si-Einheiten
% usepackage[colorlinks,
% pdfpagelabels,
% pdfstartview = FitH,
% bookmarksopen = true,
% bookmarksnumbered = true,
% linkcolor = black,
% plainpages = false,
% hypertexnames = false,
% citecolor = black]{hyperref}
usepackage{color}
usepackage{colortbl}

definecolor{hellgrau}{rgb}{0.90,0.90,0.90}

newcommand{RM}[1]{MakeUppercase{romannumeral #1{.}}}

renewcommandthesubfigure{thefigure.arabic{subfigure}}
addtokomafont{captionlabel}{bfseries}

DeclareNewTOC[
  type=scheme,                         % Name der Umgebung
  types=schemes,                       % Erweiterung (listofschemes)
  float,                               % soll gleiten
  floatpos=tbp,                        % voreingestellte Gleitparameter
  name=Scheme,                         % Name in Überschriften
  listname={Verzeichnis der Schemata}, % Listenname
                                       % counterwithin=chapter
]{los}

begin{document}

begin{table}[H]
vspace{-1.8 baselineskip}
  centering
  setlengthbelowcaptionskip{5 pt}
  caption{textbf{Reaction mixture used for the synthesis of cyclohexanone 4-nitrophenylhydrazone.}}
    begin{tabular}{cccccc}  
     cellcolor{hellgrau} chemicals   &cellcolor{hellgrau} textit{M} $^a$ (g mol$^{text{-1}}$)  &cellcolor{hellgrau} textit{n} $^a$(mol 10$^{text{-4}}$)  &cellcolor{hellgrau} textit{V} $^a$ (mL) &cellcolor{hellgrau}  textit{m} $^a$ (g) &cellcolor{hellgrau} $varrho$ $^a$ (g mL$^{text{-1}}$)
    Cyclohexanone               & 98.14   &  multicolumn{4}{c}{0.5 mL of the destillate}    
    4-Nitrophenyl hydrazine     & 153.14  &  26    &   -  & 0.4   & -     
    Sulfuric acid               & 98.08   &  372   &   2  & 3.68  & 1.84 
    Water                       & 18.02   & 1664   &   3  & 3     & 1.00 
    Ethanol                     & 47.07   & 1678   &   10 & 7.9   & 0.79    
    end{tabular} 
    vspace{0.6 baselineskip} 
    raggedright
    $^a$Molecular mass textit{M}, amount of substance textit{n}, volume textit{V}, mass textit{m},  density $varrho$.
  label{tab:ReactionMixtureCyclohexanone4-nitrophenylhydrazone}%
  vspace{-1.8 baselineskip}
end{table}

end{document}

2 Answers

Like this?

enter image description here

(red lines indicate page layout)

  • from your document example I try to make MWE (Minimal Working Example),therefore from your example are removed all packages and settings not related to your problem
  • to old version of packages or even deprecated are indicated and replaced with recent one
  • for table is used tabularx environment, its width is set to textwidth, so using them is solved your problem that table width should be equal to textwidth
  • for columns with numbers are used S columns, defined in siunitx package, which enable align numbers at their decimal points
  • since I suspect, that you in table headers indicate "footnotes", I suggest that for this is better use tnotes defined in the threeparttable and for descriptions of their meaning use table notes

MWE:

documentclass[a4paper,10pt, 
               enabledeprecatedfontcommands]{scrartcl} %Art des Dokuments, Schriftgröße etc.
usepackage[hmargin={3cm,2cm},vmargin=2cm,
            includehead]{geometry}%Maße für die wissenschaftliche Arbeit
%usepackage[utf8]{inputenc}% now is default encoding 
usepackage{lmodern}
usepackage[T1]{fontenc} %Silbentrennung
usepackage[english]{babel} %Sprachanpassungen
 
usepackage[column=O]{cellspace}                % <-- new
setlengthcellspacetoplimit{2pt}
setlengthcellspacebottomlimit{2pt}
addparagraphcolumntypes{X}
usepackage{booktabs, tabularx, % Tabellen
            threeparttable}     % new 
newcommandmcx[1]{multicolumn{1}{>{centeringarraybackslash}OX}{#1}}
renewcommandTPTtagStyle{bfseries}%for formating tags (in table, in items)

usepackage[version=4]{mhchem}  % newest version
usepackage{siunitx}% instead of units, which is deprecate
usepackage[skip=1ex, format=plain, font=small, labelfont=bf]{caption}     % new
%usepackage[labelformat=simple]{subcaption}
usepackage[table]{xcolor}  % changed, instead of "color" and "colortbl"
definecolor{hellgrau}{rgb}{0.90,0.90,0.90}
%---------------- show page layout. don't use in a real document!
usepackage{showframe}
renewcommandShowFrameLinethickness{0.15pt}
renewcommand*ShowFrameColor{color{red}}
%---------------------------------------------------------------%


begin{document}
    begin{table}[ht]
    centering
    renewcommandtabularxcolumn[1]{m{#1}}
begin{threeparttable}
caption{Reaction mixture used for the synthesis of cyclohexanone 4-nitrophenylhydrazone.}
label{tab:ReactionMixtureCyclohexanone4-nitrophenylhydrazone}
    begin{tabularx}{0.8linewidth}{l 
                                    S[table-format=3.2]
                                    S[table-format=4.0]
                                    S[table-format=2.0]
                                    S[table-format=1.1]
                                    S[table-format=1.2]
                                    }
    rowcolor{hellgrau} 
chemicals   & mcx{$M$tnote{a} (si{grampermole})}  
                & mcx{$n$tnote{b} (si{grampermole})}  
                    & mcx{$V$tnote{c}par     (si{milliliter})} 
                        & mcx{$m$tnote{d}par     (si{gram})}
                            & mcx{$varrho$tnote{e}par (si{grampermole})}          
% table body
Cyclohexanone           & 98.14   & multicolumn{4}{c}{SI{0.5}{milliliter} of the distillate} 
4-Nitrophenyl hydrazine & 153.14  &  26    & {--} & 0.4   & {--}     
Sulfuric acid           & 98.08   &  372   &   2  & 3.68  & 1.84    
Water                   & 18.02   & 1664   &   3  & 3     & 1.00    
Ethanol                 & 47.07   & 1678   &   10 & 7.9   & 0.79    
    bottomrule
    end{tabularx}
    begin{tablenotes}[flushleft, para]footnotesize
item[a]    $M$: Molecular mass
item[b]    $n$: amount of substance , 
item[c]    $V$: volume, 
item[d]    $m$: mass,  
item[e]    $varrho$: density .
    end{tablenotes}
end{threeparttable}
    end{table}
end{document}

Edit:

  • Suggested table design has width of the texwidth, however number of columns cannot be any, if you you like avoid overlaping of cells contents. With other words, it is limited by size column contents.

  • In the case that you not have numbers in table, than you can in above MWE use X column specifiers and omit use of mcx for use in column headers (but this is not a case in your code example)

IN

Correct answer by Zarko on January 10, 2021

With {NiceTabular*} of nicematrix.

documentclass{article}
usepackage{nicematrix}
usepackage{enumitem}

begin{document}
newcolumntype{-}{@{extracolsep{fill}}}

begin{table}
caption{Caption of my tabletabularnote{A tabular note.}}
begin{NiceTabular*}{textwidth}{c-c-c-c-c}%
   [code-before = rowcolor{lightgray}{1}]
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 
text & text & text & text& text 
text & text & text & text & text 
text & text & text & text & text 
text & text & text & text & text 
end{NiceTabular*}
end{table}

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Answered by F. Pantigny on January 10, 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