TransWikia.com

Tabularx: Column smaller than text

TeX - LaTeX Asked on January 22, 2021

So here is the minimal-code:

documentclass[a4paper, 12pt]{scrartcl}
usepackage{tabularx}
usepackage{chemfig}

begin{tabularx}{textwidth}{|X|c|c|X|}
    Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
    Polyethen (PE)  
            & 
            chemfig{
                H
                -[1]C 
                    (-[3]H)
                =C 
                    ( -[1]H) 
                -[7]H
            } &
            schemestart
                chemleft[
                    chemfig{
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                    }
                chemright]$_n$
            schemestop
            & Plastiktüten
    
    Polypropen (PP) 
         & chemfig{
             H
             -C
                ( -[2]H)
                ( -[6]H)
            -C
                ( -[2]H)
            =C
                ( -[1]H)
                ( -[7]H)
         } & 
         schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH3})
                    -[0]
                }
            chemright]$_n$
         schemestop
         & Flaschendeckel, Brotdosen
    
    Polyvenylchlorid (Pvc)
        & 
        chemfig{
            H
            -[1]C
                ( -[3]H)
            =C
                ( -[1]Cl)
            -[7]H
        } & 
        schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Rohrleitungen, Venylböden, Schallplatten
     
    Polyethafluorethen (PTFE) 
        & 
        chemfig{
            F
            -[1]C
                ( -[3]F)
            =C
                ( -[1]F)
            -[7]F
        }&
        schemestart
            chemleft[
                chemfig{
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Pfannenbeschichtung (Tephlon),
        Funktionskleidung (Gortex) 
end{tabularx}
end{document}

That’s how it looks like:
How it currently looks like

As you can see the text isn’t formatted in the table. Do you have an idea how I can fix this?

5 Answers

Here are two more versions of your table. In both, I have corrected the chemical formulae of the polymer molecules using polymerdelim from the chemfig package. With this command, the square brackets are correctly drawn through the outermost bonds, instead of around them. I have also corrected some of the typos in the compound names and in the application examples.

enter image description here

enter image description here

documentclass[a4paper, 12pt]{scrartcl}
usepackage[ngerman]{babel}
usepackage{tabularx}
usepackage{chemfig}
usepackage{adjustbox}
usepackage{pdflscape}
usepackage[column=0]{cellspace}
usepackage{makecell}

setlengthcellspacetoplimit{8pt}
setlengthcellspacebottomlimit{8pt}

begin{document}
begin{landscape}
noindent
begin{tabularx}{linewidth}{|0l|0c|0c|>{raggedrightarraybackslash}X|}
    Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
    & & & 
    makecell[cl]{Polyethen (PE)} 
            & 
            adjustbox{valign=c}{chemfig{
                H
                -[1]C 
                    (-[3]H)
                =C 
                    ( -[1]H) 
                -[7]H
            }} &
            schemestart
                    chemfig{
                        -[@{upleft,0.5},1]C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -[@{upright,0.5},1]
                    }
                    polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
            schemestop
            & Plastiktüten
    
   makecell[cl]{Polypropen (PP)} 
         & adjustbox{valign=c}{chemfig{
             H
             -C
                ( -[2]H)
                ( -[6]H)
            -C
                ( -[2]H)
            =C
                ( -[1]H)
                ( -[7]H)
         }} & 
         schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH_3})
                   -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
         schemestop
         & Flaschendeckel, Brotdosen
    
    makecell[cl]{Polyvinylchlorid (PVC)}
        & 
        adjustbox{valign=c}{chemfig{
            H
            -[1]C
                ( -[3]H)
            =C
                ( -[1]Cl)
            -[7]H
        }} & 
        schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
        schemestop
        & Rohrleitungen, Vinylböden, Schallplatten
     
    makecell[cl]{Polytetrafluorethen (PTFE)} 
        & 
        adjustbox{valign=c}{chemfig{
            F
            -[1]C
                ( -[3]F)
            =C
                ( -[1]F)
            -[7]F
        }}&
        schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
        schemestop
        & Pfannenbeschichtung (Teflon),
        Funktionskleidung (Goretex) 
end{tabularx}
end{landscape}



setlengthcellspacetoplimit{15pt}
setlengthcellspacebottomlimit{15pt}
renewcommand{tabularxcolumn}[1]{m{#1}}
noindent
begin{tabularx}{linewidth}{|0l|0c|0c|>{raggedrightarraybackslashhspace{0pt}}X|}
    Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
    makecell[cl]{Polyethen (PE)} 
            & 
            adjustbox{valign=c}{chemfig{
                H
                -[1]C 
                    (-[3]H)
                =C 
                    ( -[1]H) 
                -[7]H
            }} &
            schemestart
                    chemfig{
                        -[@{upleft,0.5},1]C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -[@{upright,0.5},1]
                    }
                    polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
            schemestop
            & Plastiktüten
    
   makecell[cl]{Polypropen (PP)} 
         & adjustbox{valign=c}{chemfig{
             H
             -C
                ( -[2]H)
                ( -[6]H)
            -C
                ( -[2]H)
            =C
                ( -[1]H)
                ( -[7]H)
         }} & 
         schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH_3})
                   -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
         schemestop
         & Flaschendeckel, Brotdosen
    
    makecell[cl]{Polyvinyl-chlorid (PVC)}
        & 
        adjustbox{valign=c}{chemfig{
            H
            -[1]C
                ( -[3]H)
            =C
                ( -[1]Cl)
            -[7]H
        }} & 
        schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
        schemestop
        & Rohrleitungen, Vinylböden, Schallplatten
     
    makecell[cl]{Polytetra-fluorethen (PTFE)} 
        & 
        adjustbox{valign=c}{chemfig{
            F
            -[1]C
                ( -[3]F)
            =C
                ( -[1]F)
            -[7]F
        }}&
        schemestart
                chemfig{
                    -[@{upleft,0.5},1]C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[@{right,0.5},1]
                }
                polymerdelim[delimiters ={[]}, height = 45pt, depth = 40pt, indice = n]{upleft}{upright}
        schemestop
        & Pfannenbeschichtung (Teflon),
        Funktionskleidung (Goretex) 
end{tabularx}

end{document}

Correct answer by leandriis on January 22, 2021

TeX can not hyphenate the first word of a paragraph, put

hspace*{0pt}

at the start of the X cells, for example you can add this to every X cell by using

>{hspace*{0pt}}X 

in your tabular preamble

but it may need help hyphenating the chemical terms with - depending on which natural language patterns you are using, You may need

usepackage[german]{babel} %German?

As those words will not hyphenate well with the default English patterns.

You may also consider using a smaller font so it fits better

Answered by David Carlisle on January 22, 2021

How about this other layout?

documentclass[a4paper, 12pt]{scrartcl}
usepackage[ngerman]{babel}
usepackage{tabularx}
usepackage{chemfig}

begin{document}

setlength{tabcolsep}{4pt}
setlength{extrarowheight}{2pt}
renewcommand{tabularxcolumn}[1]{m{#1}}
begin{tabularx}{textwidth}{|l|c|c|X|}
    Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
    multicolumn{4}{|l|}{Polyethen (PE)} [1ex]
            &
            chemfig{
                H
                -[1]C
                    (-[3]H)
                =C
                    ( -[1]H)
                -[7]H
            } &
            schemestart
                chemleft[
                    chemfig{
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                    }
                chemright]$_n$
            schemestop
            & Plastiktüten
    
   multicolumn{4}{|l|}{ Polypropen (PP)} [1ex]
         & chemfig{
             H
             -C
                ( -[2]H)
                ( -[6]H)
            -C
                ( -[2]H)
            =C
                ( -[1]H)
                ( -[7]H)
         } &
         schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH3})
                    -[0]
                }
            chemright]$_n$
         schemestop
         & Flaschendeckel, Brotdosen
    
    multicolumn{4}{|l|}{Polyvenylchlorid (Pvc)} [1ex]
        &
        chemfig{
            H
            -[1]C
                ( -[3]H)
            =C
                ( -[1]Cl)
            -[7]H
        } &
        schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Rohrleitungen, Venylböden, Schallplatten
    
   multicolumn{4}{|l|}{ Polyethafluorethen (PTFE)}[1ex]
        &
        chemfig{
            F
            -[1]C
                ( -[3]F)
            =C
                ( -[1]F)
            -[7]F
        }&
        schemestart
            chemleft[
                chemfig{
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Pfannenbeschichtung (Tephlon),
        Funktionskleidung (Gortex)
end{tabularx}

end{document}

enter image description here

Answered by Bernard on January 22, 2021

In addition to prefixing the X column type with a hspace{0pt} directive to enable hyphenation -- see also David's answer -- you may want to create a list of acceptable hyphenation patterns, as the babel/ngerman combination tends not be informed all that well about how words such as "Polyvenylchlorid" and "Polyethafluorethen" might be hyphenated acceptably.

enter image description here

documentclass[a4paper, 12pt]{scrartcl}
usepackage[T1]{fontenc} % to list words with Umlauts in arg. of 'hyphenation'
usepackage[ngerman]{babel}

usepackage{tabularx,ragged2e}
newcolumntype{L}{>{hspace{0pt}RaggedRight}X}
renewcommandtabularxcolumn[1]{m{#1}}

usepackage{chemfig}

% Create a list of hyphenation exceptions:
hyphenation{plastik-tüten poly-venyl-chlorid poly-etha-fluor-ethen 
   flaschen-deckel einsatz-beispiel venyl-boden venyl-böden schall-platten}

begin{document}
begin{tabularx}{textwidth}{|L|c|c|L|}
    Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
    Polyethen (PE)  
            & 
            chemfig{
                H
                -[1]C 
                    (-[3]H)
                =C 
                    ( -[1]H) 
                -[7]H
            } &
            schemestart
                chemleft[
                    chemfig{
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                    }
                chemright]$_n$
            schemestop
            & Plastiktüten
    
    Polypropen (PP) 
         & chemfig{
             H
             -C
                ( -[2]H)
                ( -[6]H)
            -C
                ( -[2]H)
            =C
                ( -[1]H)
                ( -[7]H)
         } & 
         schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH3})
                    -[0]
                }
            chemright]$_n$
         schemestop
         & Flaschendeckel, Brotdosen
    
    Polyvenylchlorid (Pvc)
        & 
        chemfig{
            H
            -[1]C
                ( -[3]H)
            =C
                ( -[1]Cl)
            -[7]H
        } & 
        schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Rohrleitungen, Venylböden, Schallplatten
     
    Polyethafluorethen (PTFE) 
        & 
        chemfig{
            F
            -[1]C
                ( -[3]F)
            =C
                ( -[1]F)
            -[7]F
        }&
        schemestart
            chemleft[
                chemfig{
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[0]
                }
            chemright]$_n$
        schemestop
        & Pfannenbeschichtung (Tephlon),
        Funktionskleidung (Gortex) 
end{tabularx}
end{document}

Answered by Mico on January 22, 2021

A small variation of @Mico answer. Used are:

  • cellspace for adding a small vertial space around cells contents
  • djustbox for vertical centering of chemfig formula

enter image description here

documentclass[a4paper, 12pt]{scrartcl}
usepackage[T1]{fontenc} % to list words with Umlauts in arg. of 'hyphenation'
usepackage[ngerman]{babel}

usepackage{ragged2e}
usepackage{cellspace, tabularx}
setlengthcellspacetoplimit{4pt}
setlengthcellspacebottomlimit{4pt}
newcolumntype{L}{>{hspace{0pt}RaggedRight}X}

usepackage{chemfig}
usepackage{adjustbox}

% Create a list of hyphenation exceptions:
hyphenation{plastik-tüten poly-venyl-chlorid poly-etha-fluor-ethen
   flaschen-deckel einsatz-beispiel venyl-boden venyl-böden schall-platten}

begin{document}
{
renewcommandtabularxcolumn[1]{m{#1}}
begin{tabularx}{textwidth}{|L|c|Sc|L|}
Name & Monomer & Polymermolekül & Einsatzbeispiel
    hline
Polyethen (PE)
    &   adjustbox{valign=c}{chemfig{
        H
        -[1]C
            (-[3]H)
        =C
            ( -[1]H)
        -[7]H}  } 
        &   schemestart
                chemleft[
                    chemfig{
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                        -C
                            ( -[2]H)
                            ( -[-2]H)
                    }
                chemright]$_n$
            schemestop
            &   Plastiktüten        
Polypropen (PP)
    &   adjustbox{valign=c}{chemfig{
         H
         -C
            ( -[2]H)
            ( -[6]H)
        -C
            ( -[2]H)
        =C
            ( -[1]H)
            ( -[7]H)}   }
        &   schemestart
              chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[2]{CH3})
                    -[0]
                }
              chemright]$_n$
            schemestop
            &   Flaschendeckel, Brotdosen   
Polyvenylchlorid (Pvc)
    &   adjustbox{valign=c}{chemfig{
        H
        -[1]C
            ( -[3]H)
        =C
            ( -[1]Cl)
        -[7]H}  }
        &
        schemestart
            chemleft[
                chemfig{
                    -[0]C
                        ( -[2]H)
                        ( -[-2]H)
                    -C
                        ( -[6]H)
                        ( -[2]{Cl})
                    -[0]
                }
            chemright]$_n$
        schemestop
            & Rohrleitungen, Venylböden, Schallplatten
    
Polyethafluorethen (PTFE)
    &   adjustbox{valign=c}{chemfig{
        F
        -[1]C
            ( -[3]F)
        =C
            ( -[1]F)
        -[7]F}  }
        &   schemestart
              chemleft[
                chemfig{
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -C
                        ( -[2]F)
                        ( -[6]F)
                    -[0]
                }
              chemright]$_n$
            schemestop
        &   Pfannenbeschichtung (Tephlon), Funktionskleidung (Gortex)
end{tabularx}
}
end{document}

Answered by Zarko on January 22, 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