Graphics, Figures & TablesTables-Tabularx-Equal width and centering of cell contents

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
saravanan
Posts: 3
Joined: Mon Dec 29, 2008 7:48 pm

Tables-Tabularx-Equal width and centering of cell contents

Post by saravanan »

Hi all,

I am new to Latex and also to this community. I need some help with tabularx package. I spent whole two days and can't figure it out. Finally I got things of equal width to work... the contents are left justified though. Please help me to have the contents centered.

I am attaching the code here

Code: Select all

\begin{table}[!ht]
\begin{center}
\caption{Reynolds number for different flow conditions} \vspace{0.2in}
\begin{tabularx}{0.6\linewidth}{p{2cm}|X|X|X|X}
\hline \multicolumn{1}{c|}{} & \multicolumn{4}{c}{\bf Kinematic Viscosity ($mm^2/s$)}\\
\hline
{\bf Flow Rate} & \multirow{2}{*}{\bf 1} & \multirow{2}{*}{\bf 10} & \multirow{2}{*}{\bf 20} & \multirow{2}{*}{\bf 30} \\
      {($mL/s$)} & {} & {} & {} & {} \\[0.5ex]
\hline
4 & 8.35 & 0.84 & 0.42 & 0.28 \\
5 & 10.44 & 1.04 & 0.52 & 0.35 \\
\hline
\end{tabularx}
\label{tab_reynoldstab}
\end{center}
\end{table}
Anticipating response,
Saravanan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: Tables-Tabularx-Equal width and centering of cell contents

Post by josephwright »

Not exactly an answer, but presented with your data I would lay things out a little differently. The following uses float and caption to space the table caption nicely, booktabs to get "good" rules in tables and siunitx for aligning on the decimal point:

\documentclass{article}
\usepackage{booktabs,caption,float,multirow,siunitx,tabularx}
\floatstyle{plaintop}
\restylefloat{table}
\begin{document}

\begin{table}
\begin{center}
\caption{Reynolds number for different flow conditions}
\label{tab_reynoldstab}
\sisetup{tabformat=2.2}
\begin{tabular}{cSS}
\toprule
\textbf{Kinematic} & \multicolumn{2}{c}{\textbf{Reynolds Number}} \\
\textbf{Viscosity}/\si{\milli\metre\per\second} &
\multicolumn{2}{c}{At flow rate} \\
& {\SI{4}{\milli\liter\per\second}}
& {\SI{5}{\milli\liter\per\second}} \\
\midrule
1 & 8.35 & 10.44 \\
10 & 0.84 & 1.04 \\
20 & 0.42 & 0.52 \\
30 & 0.28 & 0.35 \\
\bottomrule
\end{tabular}
\end{center}
\end{table}

\end{document}
--
Joseph Wright
Joseph Wright
saravanan
Posts: 3
Joined: Mon Dec 29, 2008 7:48 pm

Re: Tables-Tabularx-Equal width and centering of cell contents

Post by saravanan »

Thank you for your time and reply. I tried and it complains about tabular{cSS} stuff and also I think I do not have siunits.sty file. But I adopted the booktabs thing and it looks neat. I appreciate your help.

Cheers.
Saravanan
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: Tables-Tabularx-Equal width and centering of cell contents

Post by josephwright »

No problem. I write siunitx, so of course I have it :-) Seriously, it is in TeXLive 2008 and MiKTeX 2.7, but if you have an older system you would have had to download it yourself from CTAN.
--
Joseph Wright
Joseph Wright
User avatar
Stefan Kottwitz
Site Admin
Posts: 10344
Joined: Mon Mar 10, 2008 9:44 pm

Tables-Tabularx-Equal width and centering of cell contents

Post by Stefan Kottwitz »

Hi Saravanan,

welcome to the board!
Instead of X you could try

Code: Select all

>{\centering\arraybackslash}X
each time. Or use \newcolumntype to define a new column style. Have a look at the documentation of the array package if you want to read about the >, \arraybackslash or the \newcolumntype macro.

Btw. I wouldn't use italic units (perhaps have a look at the package siunitx) and I wouldn't use that much vertical lines. Instead of \centering the numbers could be aligned at their decimal points. Just some ideas.

Stefan
LaTeX.org admin
saravanan
Posts: 3
Joined: Mon Dec 29, 2008 7:48 pm

Re: Tables-Tabularx-Equal width and centering of cell contents

Post by saravanan »

Thanks Stefan. I know, it has been a long time since I last visited this site. I downloaded Siunits package and from what Joesph has replied earlier, I think I know now to include the package. But, where should I have the source file of siunitx? When I downloaded, it is in a folder inside which there are many folders. Do I have to take the siunitx style file and keep it in the same folder where my main tex file is there? I am lacking some basics here. Is there any documentation for using that package?

Thanks.
Saravanan
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Tables-Tabularx-Equal width and centering of cell contents

Post by localghost »

You didn't clarify which LaTeX distribution you are using. Package installation on a MiKTeX system is best done with the package manager. And TeX Live 2008 also comes with such a helpful tool (tlmgr).


Best regards
Thorsten¹
Post Reply