3

I'm trying to get a table that automatically inserts a line-break so some very long text can fit in the cell, instead of overflowing to the margins like it's doing now. I tried with \makecell but didn't work.

I've also tried breaking the line manually (even if it's not the ideal solution) with \ \ but again, didn't work either.

It's a complex table because it has some combined cells.

This is my attempt:

\usepackage{multirow}
\usepackage{tabularx}

\begin{document}

\begin{table}[htbp]
    \centering
\begin{tabularx}{\textwidth}{|l|l|X|}
\hline
     Allele & Guide RNA & Repair template \\
     \hline
     \hline
     allele1 & GuideRNA#1 & ATTATCCATGGAACGTTCACCGTATTGTTCATCTTCAGcTGaCAACTTATATCGATTCTCGCGAATCTTCCACTTGC\\
     \hline
     allele2 & \begin{tabular}{@{}l@{}}
                   GuideRNA2.1 \\
                   GuideRNA2.2\\
                 \end{tabular} & AATATTATACAAACgTCGAATATTGTACaTTGTCGATATTGTCGAACATATATTAATCCATATGTATATCTTCCTGAT\\
    \hline
     allele3 & \begin{tabular}{@{}l@{}}
                   GuideRNA3.1 \\
                   GuideRNA3.2 \\
                 \end{tabular} & GACACTCGAAGAGAAGCTTCCGCAATATGTATGCTTTCAGTCAACACTACTCTATACCTCGAGCAAGGGTGATCGTCGTATTCGAGTACATACAATGTGCCTT\\
    \hline
    allele4 & GuideRNA4 & AACGTTCACCGTATTGTTCATCTTCAGTTGGCAACTTATATCGATTCTCGaGAATCTTCCAtTgGCaTTCTACCACATTTACACATACGCCAAACGCCCAGTGATGTCTGGACCAGG\\
     \hline
\end{tabularx}
\end{table}
\end{center}

\end{document}

but this is how it looks like: [1

Ideally, it'd look like this one (made in Word):

enter image description here

2
  • Welcome to TeX.SE.
    – Mico
    Commented Aug 11, 2020 at 17:19
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – TobiBS
    Commented Aug 11, 2020 at 17:33

1 Answer 1

4

The strings in the final column aren't human-language "words" and thus won't be line-broken sensibly by TeX's default hyphenation algorithm. I suggest you use the \seqsplit macro (provided by the seqsplit package) to force the automated insertion of suitable linebreaks.

I'd also like to encourage you to give the table a more open "look" by getting rid of all vertical rules and by employing fewer, but well-spaced, horizontal rules, using the macros of the booktabs package.

enter image description here

\documentclass{article}
\usepackage{tabularx,seqsplit}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{booktabs}

\begin{document}
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{@{} llX @{}}
\toprule
Allele & Guide RNA & Repair template \\
\midrule
allele1 & GuideRNA1 & 
\seqsplit{ATTATCCATGGAACGTTCACCGTATTGTTCATCTTCAGcTGaCAACTTATATCGATTCTCGCGAATCTTCCACTTGC}\\
\addlinespace
allele2 & \begin{tabular}{@{}l@{}}
             GuideRNA2.1 \\
             GuideRNA2.2\\
          \end{tabular} & 
\seqsplit{AATATTATACAAACgTCGAATATTGTACaTTGTCGATATTGTCGAACATATATTAATCCATATGTATATCTTCCTGAT}\\
\addlinespace
allele3 & \begin{tabular}{@{}l@{}}
            GuideRNA3.1 \\
            GuideRNA3.2 \\
          \end{tabular} & 
\seqsplit{GACACTCGAAGAGAAGCTTCCGCAATATGTATGCTTTCAGTCAACACTACTCTATACCTCGAGCAAGGGTGATCGTCGTATTCGAGTACATACAATGTGCCTT}\\
\addlinespace
allele4 & GuideRNA4 & 
\seqsplit{AACGTTCACCGTATTGTTCATCTTCAGTTGGCAACTTATATCGATTCTCGaGAATCTTCCAtTgGCaTTCTACCACATTTACACATACGCCAAACGCCCAGTGATGTCTGGACCAGG}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .