TransWikia.com

Enumeration and line break tabularx

TeX - LaTeX Asked by Elia on January 4, 2021

I try to do an enumeration / line break in my chart but I am not able to do it. Could you help me to find the right tool?

For the row Advantages I try to get
no genomic integration (no frameshift, or even worse damage to the genome)
=> linebreak
high flexibility

And for row cultured cells i try to enumerate the following 3 words: electroporation / lipofection / microinjection

Thank you

% page setup 
documentclass[a4paper, 11pt]{article}
usepackage[left=3cm,top=3cm,right=3cm]{geometry}
usepackage{fancyvrb} 

% tables
usepackage{booktabs} 
usepackage{tabularx} 
newcolumntype{C}{>{Centering}X}
newcolumntype{P}[1]{>{RaggedRighthspace{0pt}}m{#1}}

begin{document}

begin{table}[ht]
scriptsize
newlengthcolwidth 
settowidthcolwidth{30% acrylamide stock solution30%} % set width of 1st col.
begin{tabularx}{textwidth}{@{} P{colwidth} *{2}{C} @{}}
    toprule
& Transient transfection & Stable transfection
    midrule
Advantages
    & no genomic integration (no frameshift, or even worse damage to the genome) high flexibility & 
addlinespace
cultured cells
    & electroporation / lipofection / microinjection
bottomrule
end{tabularx}
endtabularx
end{table}

end{document}



2 Answers

Two examples for use itemize and enumerate in your table and one example with different table design:

documentclass[a4paper, 11pt]{article}
usepackage[margin=3cm]{geometry}
usepackage{fancyvrb}

% tables
usepackage{ragged2e}   % <--- added
usepackage{booktabs, tabularx}
newcolumntype{C}{>{Centering}X}
newcolumntype{L}{>{RaggedRighthspace{0pt}}X} % <--- new, for the last example
newcolumntype{P}[1]{>{RaggedRighthspace{0pt}}m{#1}}
newlengthcolwidth

usepackage{enumitem}   % <--- new, for lists (in table)
usepackage{etoolbox}   % <--- new, for customization of lists used in tables
AtBeginEnvironment{table}{%
setlist[itemize]{nosep,
                 leftmargin=*,
                 label=textbullet, % <---
                 before=begin{minipage}[t]{linewidth}, 
                 after=end{minipage}}                   

setlist[enumerate]{nosep,
                 leftmargin=*,
                 label=arabic*.,   % <---
                 before=begin{minipage}[t]{linewidth},  
                 after=end{minipage}}                   
                        }

begin{document}
With verb+itemize+
    begin{table}[ht]
settowidthcolwidth{30% acrylamide stock solution30%} % set width of 1st col.
%
begin{tabularx}{textwidth}{@{} P{colwidth} *{2}{C} @{}}
    toprule
    & Transient transfection & Stable transfection  
    midrule
Advantages
    &   begin{itemize}
    item   no genomic integration (no frameshift, or even worse damage to the genome) 
    item   high flexibility 
        end{itemize}   &   
addlinespace
cultured cells
    &   begin{itemize}
    item   electroporation 
    item   lipofection 
    item    microinjection
        end{itemize}   &   
bottomrule
end{tabularx}
    end{table}
    
or with verb+enumerate+:

    begin{table}[ht]
settowidthcolwidth{30% acrylamide stock solution30%} % set width of 1st col.
%
begin{tabularx}{textwidth}{@{} P{colwidth} *{2}{C} @{}}
    toprule
    & Transient transfection & Stable transfection  
    midrule
Advantages
    &   begin{enumerate}
    item   no genomic integration (no frameshift, or even worse damage to the genome)
    item   high flexibility
        end{enumerate}   &   
addlinespace
cultured cells
    &   begin{enumerate}
    item   electroporation
    item   lipofection
    item   microinjection
        end{enumerate}   &   
bottomrule
end{tabularx}
    end{table}
    
or with verb+l+ and verb+L+ types of table columns and verb+enumerate+:

    begin{table}[ht]
begin{tabularx}{textwidth}{@{} l *{2}{L} @{}}
    toprule
    & Transient transfection & Stable transfection  
    midrule
Advantages
    &   begin{enumerate}
    item   no genomic integration (no frameshift, or even worse damage to the genome)
    item   high flexibility
        end{enumerate}   &   
addlinespace
cultured cells
    &   begin{enumerate}
    item   electroporation
    item   lipofection
    item   microinjection
        end{enumerate}   &   
bottomrule
end{tabularx}
    end{table}
end{document}

enter image description here

Addendum: In a case that you like to have only line breaks. IN such a cases you not need enumitem and etoolbox` packages:

documentclass[a4paper, 11pt]{article}
usepackage[margin=3cm]{geometry}
usepackage{fancyvrb}

% tables
usepackage{ragged2e}   % <--- added
usepackage{booktabs, tabularx}
newcolumntype{L}{>{RaggedRighthspace{0pt}}X} % <--- new, for the last example

begin{document}
...

This you can achieve on three ways:

  • insert empty lines where you like to break cell's content:
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)

        high flexibility
        &   
  • use command `verb+linebreak+
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)linebreak
        high flexibility
        &   
  • or use of command par
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)par
        high flexibility
        &   

In all above cases the result is the same:

enter image description here

Correct answer by Zarko on January 4, 2021

You are lacking the inclusion of ragged2e in your preamble:

enter image description here

documentclass{article}

% tables
usepackage{booktabs,ragged2e}
usepackage{tabularx} 
newcolumntype{C}{>{Centering}X}
newcolumntype{P}[1]{>{RaggedRight}m{#1}}

begin{document}

begin{table}[ht]
  scriptsize
  newlengthcolwidth
  settowidthcolwidth{30% acrylamide stock solution30%} % set width of 1st col.
  begin{tabularx}{textwidth}{@{} P{colwidth} *{2}{C} @{}}
    toprule
      & Transient transfection & Stable transfection 
    midrule
    Advantages
      & no genomic integration (no frameshift, or even worse damage to the genome) high flexibility & 
    addlinespace
    cultured cells
      & electroporation / lipofection / microinjection 
    bottomrule
  end{tabularx}
end{table}

end{document}

Answered by Werner on January 4, 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