2

I have created the table to render my output, where the name of the sample is rather long, so I need to split, because without splitting, sharelatex won't print out the table all. However, I used \\ to break the string, but it creates space, output latex table is not desired to me. Can anyone point me out how to optimize this? Any better idea?

Here is the code I used:

\begin{table}[h!]
  \centering
  \caption{output list}
  \label{tab:table1.1}
  \begin{tabular}{ccccc}
    \toprule
    Sample name & R\textsuperscript{sc} & R\textsuperscript{sd} & R\textsuperscript{wc} & R\textsuperscript{wd}\\
    \midrule
    wgEncodeOpenChromChip\\K562CmycAlnRep2 & {Myc1\_2} & 8763362 & 32850 & 311409\\
    wgEncodeOpenChromChip\\K562CmycAlnRep3 & {Myc1\_3} & 9649688 & 13623 & 104911\\
    \bottomrule
  \end{tabular}
\end{table}

Here is the output of above code: enter image description here

but the output of above code is not desired for me, I want to split the long character into newline but without spacing. How can I make this happen? Any better idea? Thanks a lot

Edit: If I didn't break the long string, sharelatex didn't print me out rest of column in the table. If I break the string, it introduces space. Any better solution to optimize the code? I am quite new in latex community. Hope my post is clear.

4
  • @Mico for me this is fine ` wgEncodeOpenChromChip\\K562CmycAlnRep2`, but not well desired because as you see from the code, after splitting the long string, it has space between first part and second part, I don't want this. Any better idea?
    – Jerry07
    Mar 16, 2017 at 15:47
  • I think the problem is, that we don't see your problem clearly. When you add a linebreak, you get space - naturally. Maybe if you would add an image, in which you mark the problem it would be easier to help.
    – Timm
    Mar 16, 2017 at 15:51
  • @Timm Dear Timm, I updated the post. Could you point me out any direction to fix this issue? Or if I don't break the long string, is that possible to let sharelatex print out all column? Any idea please? Thank you
    – Jerry07
    Mar 16, 2017 at 16:00
  • To explain your problem: You defined your table with a c column. This type of column does not support a manual linebreak. So what happens at `\` is that a new row in the table is started, which is why you get additional vertical space.
    – Timm
    Mar 16, 2017 at 16:19

1 Answer 1

1

Maybe something like this?

enter image description here

If you prefer top-alignment instead of vertical centering, use p instead of m as the column type for the first column.

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}     % for 'm' column type
\newlength\mylen
\settowidth\mylen{wgEncodeOpenChromChip} % determine width of 1st col.
\begin{document}
\begin{table}
\centering
  \caption{output list}
  \label{tab:table1.1}
\begin{tabular}{@{}m{\mylen}cccc@{}}
    \toprule
    Sample name & R\textsuperscript{sc} & R\textsuperscript{sd} 
                & R\textsuperscript{wc} & R\textsuperscript{wd}\\
    \midrule
    wgEncodeOpenChromChip K562CmycAlnRep2 & {Myc1\_2} & 8763362 & 32850 & 311409\\
    wgEncodeOpenChromChip K562CmycAlnRep3 & {Myc1\_3} & 9649688 & 13623 & 104911\\
    \bottomrule
\end{tabular}
\end{table}
\end{document}
3
  • Dear Mico, one beginner question, I create this table in one particular chapter. can I put this code \newlength\mylen; \settowidth\mylen{wgEncodeOpenChromChip} inside the code of table ? I am sorry for this simple question.
    – Jerry07
    Mar 16, 2017 at 16:10
  • 1
    @Dan - I'd put \newlength\mylen in the preamble. It's ok to place \settowidth\mylen{<some string>} after \begin{table} and before \begin{tabular}.
    – Mico
    Mar 16, 2017 at 16:13
  • sorry for wrong question. I figure out the issue. Many thanks :)
    – Jerry07
    Mar 16, 2017 at 16:20

You must log in to answer this question.

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