Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have some columns with a very short entries on the first column and a rather long entry on the second column.

\begin{ctabular}{\textwidth}{ll}
  \toprule
  Name & Recipe\\
  \midrule
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  \bottomrule
\end{ctabular}

The table actually has a lot of rows and spans multiple pages, hence why I'm using ctabular (from the memoir class). I want to set the width of the table to \textwidth. I'll be happy with whatever LaTeX picks for the first column in order to have the name in one line, and want the second to take the rest of the space. How can I accomplish this?

I do not want to set the size of each column individually so it doesn't break when I add a new row with a longer name, or change the font size for example.

share|improve this question
    
    
@ADP thanks but that does not solve my problem. In that question, one column is set to a specific value and the other to fill the rest. Instead of setting a specific value, I want it to be whatever is needed to have all entries in one line, and use whatevers left to the other column. Also, I don't think the tabularx package deals with the multipage table issue. –  carandraug Jan 26 '13 at 4:56
1  
There is something like ltxtable - longtable meets tabularx. –  Werner Jan 26 '13 at 5:53
add comment

1 Answer

up vote 4 down vote accepted

You can do this with the help of the eqparbox package. There is actually an example of that type in its documentation, but it uses a custom list environment rather than a tabular environment.

In the following I use also longtable because, for reasons unknown to me, when trying the exact same thing with ctabular the horizontal rules came out wrong. Replacing ctabular with longtable fixed this. Two runs are necessary to get the table right.

\documentclass{memoir}
\usepackage{eqparbox}
\usepackage{longtable}
\usepackage{lipsum}

\begin{document}


\lipsum[1-2]

\newsavebox{\firstentrybox}
\newcolumntype{S}{%
>{\begin{lrbox}{\firstentrybox}}%
l%
<{\end{lrbox}%
\eqmakebox[firstentry][l]{\unhcopy\firstentrybox}}}

\begin{longtable}{S p{\dimexpr(\textwidth-\eqboxwidth{firstentry}-4\tabcolsep)}}
  \toprule
  Name & Recipe\\
  \midrule
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Freezing media         & 91\% FCS; 10\% DMSO \\
  Growth medium (HeLa)   & 87\% DMEM; 10\% FCS; 1\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  Growth medium (horse)  & 76\% DMEM; 20\% FCS; 2\% NEAA; 1\% Penicillin/Streptomycin); 1\% L-Glutamine \\
  \bottomrule
\end{longtable}

\end{document}

output

output page 2

share|improve this answer
    
works like a charm. I can confirm that using ctabular was also messing the bottom and mid rules. –  carandraug Jan 26 '13 at 18:22
1  
@carandraug I have since realized that S is the letter used by the siunitx package for a specific column type. So perhaps some other letter should be used here if you ever need to use siunitx. –  jfbu Jan 26 '13 at 18:24
    
that was awesome good timing. I am indeed using siunitx in that table (I took them away from the table to make a simpler example), and start getting the errors once I added them again. Thank you –  carandraug Jan 26 '13 at 18:28
    
I will buy a lottery ticket immediately! –  jfbu Jan 26 '13 at 18:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.