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 a table that I would like to adjust: the text is floatting; I wanna have it centred in every cell.

  \documentclass[12pt,a4paper,oneside]{book}
  \usepackage{tensor}
  \usepackage{graphicx}
  \begin{document}

  \begin{table}
  \centering
  \begin{tabular}{|p{3cm}|p{2cm}|p{2.3cm}|p{1.5cm}|p{4cm}|}
  \hline 
  \center{Radionuclide padre} & \center{T$_{1/2}$ (anni)} & \center{Abbondanza isotopica} & \center{Elemento figlio} & \center{Materiali databili} \tabularnewline   \hline \hline
  \center{\nuclide[14][]{C}} & \center{5730} & \center{-} & \center{\nuclide[14][]{N}} & \center{Materiali organici} \tabularnewline \hline
   \center{\nuclide[235][]{U}} & \center{723 milioni} &\center{ 0.72}&     \center{\nuclide[207][]{Pb}} & \center{Zirconide, Uranite, Pechblenda} \tabularnewline \hline 
   \center{\nuclide[40][]{K}} & \center{1'300 milioni} & \center{0.012} &   \center{\nuclide[40][]{Ar}} & \center{Muscovite, Biotite, Orneblenda, Feldspato potassico, Rocce vulcaniche}\tabularnewline
  \hline 
  \center{\nuclide[238][]{U}} & \center{4'510 milioni} & \center{99.27} &  \center{\nuclide[206][]{Pb}}& \center{Zircone, Uraninite, Pechblenda}\tabularnewline  \hline 
  \center{\nuclide[232][]{T}} & \center{13'900 milioni} & \center{100} &  \center{\nuclide[208][]{Pb}}& \center{Rocce vulcaniche}\tabularnewline \hline 
  \center{\nuclide[87][]{Ru}} & \center{47'000 milioni} & \center{27.87} &    \center{\nuclide[87][]{St}}& \center{Miche, Feldspati potassici, Rocce metamorfiche}\tabularnewline
 \hline 
 \end{tabular}

  \end{table}
  \end{document}
share|improve this question
1  
You should tell people where \nuclide is defined. Or better yet: make the example a complete, i.e., compilable one. –  cgnieder Jan 9 '13 at 22:32
    
could you make a complete minimal working example (MWE) –  cmhughes Jan 9 '13 at 22:35
    
Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. :) –  hpesoj626 Jan 9 '13 at 22:39
add comment

1 Answer 1

up vote 5 down vote accepted

Your usage of \center is wrong: it's not a command taking an argument and actually it should never be used (it exists only because of the center environment).

Here's a better way to center columns with predefined width

\documentclass{article}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

% A definition of \nuclide, since yours is missing    
\usepackage{xparse}
\NewDocumentCommand{\nuclide}{O{} O{} m}
 {$\vphantom{\mbox{#3}}^{#1}_{#2}$#3}

\begin{document}
\begin{table}
\centering
\begin{tabular}{|P{3cm}|P{2cm}|P{2.3cm}|P{1.5cm}|P{4cm}|}
\hline 
X & X & X & X & X    
\tabularnewline         
\hline \hline
\nuclide[14][]{C} & 5730 & - & N & long text \tabularnewline \hline
\nuclide[235][]{U} & 723 milioni & 0.72&         
\nuclide[207][]{Pb} & Long text    
\tabularnewline \hline 
\nuclide[40][]{K} & 1'300 milioni & 0.012 &    
\nuclide[40][]{Ar} & Long text\tabularnewline
\hline 
\nuclide[238][]{U} & 4'510 milioni & 99.27 &     
\nuclide[206][]{Pb}& Long text\tabularnewline   
\hline 
\nuclide[232][]{T} & 13'900 milioni & 100 &   
\nuclide[208][]{Pb}& long text\tabularnewline \hline 
\nuclide[87][]{Ru} & 47'000 milioni & 27.87 &  
\nuclide[87][]{St}& Long text\tabularnewline
\hline 
\end{tabular}

\end{table}
\end{document}

enter image description here

However, I don't see why having predefined column width, since they seem to be computed at random.

There are some other flaws in the table; thousands should never be separated by apostrophes or raised dots or commas, but just by a thin space. Separating cells with vertical rules makes them almost unreadable: I use to say that vertical rules are barrier to the reader.

Here's another version of your table:

\documentclass{article}

\usepackage{booktabs,siunitx}

% A definition of \nuclide, since yours is missing    
\usepackage{xparse}
\NewDocumentCommand{\nuclide}{O{} O{} m}
 {$\vphantom{\mbox{#3}}^{#1}_{#2}$#3}

\begin{document}

\begin{table}
\centering
\begin{tabular}{*{4}{c}p{5cm}}
\toprule
X & X & X & X & X \\
\midrule
\nuclide[14][]{C}  & \num{5730}    & ---         & N &
  long text \\
\nuclide[235][]{U} & \num{723e6}   & \num{0.72}  & \nuclide[207][]{Pb} &
  Long text \\
\nuclide[40][]{K}  & \num{1300e6}  & \num{0.012} & \nuclide[40][]{Ar}  & 
  Long text \\
\nuclide[238][]{U} & \num{4510e6}  & \num{99.27} & \nuclide[206][]{Pb} & 
  Long text \\
\nuclide[232][]{T} & \num{13900e6} & \num{100}   & \nuclide[208][]{Pb} &
  long text \\
\nuclide[87][]{Ru} & \num{47000e6} & \num{27.87} & \nuclide[87][]{St}  &
 Long text \\
\bottomrule
\end{tabular}

\end{table}
\end{document}

enter image description here


Here's a complete version with the data supplied; notice that the headers are split into two rows, because they won't fit in only one. The only predefined width is in the last column, the others will occupy as much space as they need.

\documentclass{article}
\usepackage{array,booktabs,siunitx}

\usepackage{tensor}

\begin{document}
\begin{table}
\centering
\addtolength{\tabcolsep}{-2pt} % slight reduction of intercolumn space
\begin{tabular}{*{4}{c} >{\raggedright\arraybackslash}p{3.5cm}}
\toprule
Radionuclide & T$_{1/2}$ & Abbondanza & Elemento & Materiali databili \\
padre        & (anni)    & isotopica  & figlio   &                    \\
\midrule
\nuclide[14][]{C}  & \num{5730}    & ---         & N &
  Materiali organici \\
\nuclide[235][]{U} & \num{723e6}   & \num{0.72}  & \nuclide[207][]{Pb} &
  Zirconide, Uranite, Pechblenda \\
\nuclide[40][]{K}  & \num{1300e6}  & \num{0.012} & \nuclide[40][]{Ar}  & 
  Muscovite, Biotite, Orneblenda, Feldspato potassico, Rocce vulcaniche \\
\nuclide[238][]{U} & \num{4510e6}  & \num{99.27} & \nuclide[206][]{Pb} & 
  Zircone, Uraninite, Pechblenda \\
\nuclide[232][]{T} & \num{13900e6} & \num{100}   & \nuclide[208][]{Pb} &
  Rocce vulcaniche \\
\nuclide[87][]{Ru} & \num{47000e6} & \num{27.87} & \nuclide[87][]{St}  &
 Miche, Feldspati potassici, Rocce metamorfiche \\
\bottomrule
\end{tabular}

\end{table}
\end{document}

enter image description here

You may consider adding \addlinespace between the rows to detach them from one another:

\documentclass{article}
\usepackage{array,booktabs,siunitx}

\usepackage{tensor}

\begin{document}
\begin{table}
\centering
\addtolength{\tabcolsep}{-2pt} % slight reduction of intercolumn space
\begin{tabular}{*{4}{c} >{\raggedright\arraybackslash}p{3.5cm}}
\toprule
Radionuclide & T$_{1/2}$ & Abbondanza & Elemento & Materiali databili \\
padre        & (anni)    & isotopica  & figlio   &                    \\
\midrule
\nuclide[14][]{C}  & \num{5730}    & ---         & N &
  Materiali organici \\
\addlinespace
\nuclide[235][]{U} & \num{723e6}   & \num{0.72}  & \nuclide[207][]{Pb} &
  Zirconide, Uranite, Pechblenda \\ 
\addlinespace
\nuclide[40][]{K}  & \num{1300e6}  & \num{0.012} & \nuclide[40][]{Ar}  & 
  Muscovite, Biotite, Orneblenda, Feldspato potassico, Rocce vulcaniche \\ 
\addlinespace
\nuclide[238][]{U} & \num{4510e6}  & \num{99.27} & \nuclide[206][]{Pb} & 
  Zircone, Uraninite, Pechblenda \\ 
\addlinespace
\nuclide[232][]{T} & \num{13900e6} & \num{100}   & \nuclide[208][]{Pb} &
  Rocce vulcaniche \\ 
\addlinespace
\nuclide[87][]{Ru} & \num{47000e6} & \num{27.87} & \nuclide[87][]{St}  &
 Miche, Feldspati potassici, Rocce metamorfiche \\
\bottomrule
\end{tabular}

\end{table}
\end{document}

enter image description here

share|improve this answer
    
@FordPrefect Yes, it does: I simply copied the result of compiling the examples. What doesn't work? –  egreg Jan 9 '13 at 22:54
    
@FordPrefect What's the problem? The line wraps because you're not giving enough room for the text to stay in one line. However, why using the word "milioni" when "× 10^6" is very common practice? –  egreg Jan 9 '13 at 22:55
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.