1

I have a table with words separated by commas. Latex puts additional spaces in between these words which look a bit odd.

  \begin{table*}[!tb]
\begin{center}
\begin{scriptsize}
\begin{tabular} {|p{0.8in}|p{2.75in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.3in}| }
\hline
{\bf Features} & {\bf Feat Selection} &   \multicolumn{3}{c|}{\bf F\_score } \\ \hline
&&&favor&against&average \\ \hline
\bf Aaaaaaaa & uuuuuuuu,  bnnnnn,  general\_ddd,  llll\_ddd,  sddddddddd\_combined\_ddd & none & 0.71&0.64 & 0.67\\ \hline
\bf Abbbbbbb & uuuuuuuu, bnnnnn,  general\_ddd,  llll\_ddd,  sddddddddd\_combined\_ddd & none &0.73&0.66 & 0.69\\ \hline
\bf Ffffffffff & uuuuuuuu, bnnnnn,  general\_ddd,  llll\_ddd,  stttttttt\_combined\_dtt, POS\_bmmmmm & crrrrrrrrr &  0.55&0.57&0.56\\ \hline
\end{tabular}
\end{scriptsize}
\begin{small}
\caption{\label{results} Best performing model.}
\end{small}
\end{center}
\end{table*}


\begin{table*}[!htb]
\begin{center}
\begin{scriptsize}
\begin{tabular} {|p{0.8in}|p{2.15in}|p{2.15in}|r|}
\hline
{\bf Topic} &  \multicolumn{2}{|c|} {\bf Seed Hhhhhhhh } & \bf Tttttt  \\ \hline
\bf kkkkkkkk &  \#YayFeminism, \#YesAllWomen, \#FeministsAreBeautiful & \#AntiFeminism, \#AntiFeminist, \#WomenAgainstFeminism  &  4446 \\ \hline
\bf Hhhhhhh Cccccc  & \#ImWithHer, \#HillYes, \#ITrustHillary, & \#StopHillary, \#HillaryForPrison, \#OhHillNo & 8529 \\ \hline
\end{tabular}
\end{scriptsize}

This is what I get enter image description here This has additional spaces in Feat selection column and seed column. How can I remove these to have normal spacing.

1
  • Welcome :). Note, I have added another suggestion, at the end of the post. This one would change the table a bit, but you may like it better. See the post I link to for a little more, and for docs.
    – zdim
    Commented Apr 6, 2016 at 19:54

2 Answers 2

2

Update:   Turn off hyphenation only for select text, full example.

This seems to be happening because Latex is struggling to format the line, and in the shortened space in a table cell the hyphenation may not make it any better. You can

  • Tweak hyphenation. One good way of doing it is by using the package hyphenat. Then you can turn off hyphenation for select parts of text via \nohyphens{text}. See this post for far more on this, and for other ways (with shortcomings but that may work perfectly in this case).
  • Then, the text may not look nice. To improve that you can flush it to one side, for example with \raggedright to left-justify, see Paragraph alignment. You can also use the \begin{flushleft} ... \end{flushleft} environment, but this is going to be unwieldy with table and cells.

Example of using the package and \raggedright. Note -- I found that the mere use of the packages improves hyphenation of your examples, by its defaults. There are other settings in the package that you can tweak.

\usepackage{hyphenat}

% first table exactly the same but looking better with the package

\begin{table*}[!htb]
\begin{center}
\begin{scriptsize}
\begin{tabular} {|p{0.8in}|p{2.15in}|p{2.15in}|r|} \hline
{\bf Topic} & \multicolumn{2}{|c|} {\bf Seed Hhhhhhhh } & \bf Tttttt \\ \hline 
    \bf kkkkkkkk   
    & \raggedright \nohyphens{
      \#YayFeminism, \#YesAllWomen, \#FeministsAreBeautiful}
    & \raggedright \nohyphens{ 
      \#AntiFeminism, \#AntiFeminist, \#WomenAgainstFeminism}  
    &  4446 \\ \hline
    \bf Hhhhhhh Cccccc
    & \raggedright \#ImWithHer, \#HillYes, \#ITrustHillary,
    & \raggedright \#StopHillary, \#HillaryForPrison, \#OhHillNo 
    & 8529 \\ \hline
\end{tabular}
\end{scriptsize}
\end{center}
\end{table*}

I've broken the lines for readability here.

table example


Added note

I'd recommend to look into the booktabs package, demonstrated in this recent post, for example. Its use is very simple. It is considered to produce more professional looking tables. (There is some taste involved, of course.) Your second table would look like this

table with booktabs

The only changes to code are: add \usepackage{booktabs}, then replace all of \hline with:

  • \toprule for the header line)
  • \midrule for others (may not need all of them!)
  • \bottomrule for the last one

Also, remove vertical lines. They seldom help, and here your text nicely lines up forming a visual guide.

2

After some fiddling with the formatting for me, \RaggedRight from the package ragged2e worked better as it does not totally suppress hyphenation.

\begin{tabular} {|p{0.8in}|>{\RaggedRight}p{2.5in}|p{2.15in}|r|}

You must log in to answer this question.

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