表格问题

表格问题

我有一张想要调整的表格:文本是浮动的;我想让它在每个单元格中居中。

  \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}

答案1

你的用法\center是错误的:它是不是一个带有参数的命令,实际上它永远不应该被使用(它仅仅因为环境而存在center)。

这是将具有预定义宽度的列居中的更好方法

\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}

在此处输入图片描述

但是,我不明白为什么要预定义列宽,因为它们似乎是随机计算的。

表格中还有其他一些缺陷;千位不应该用撇号、凸点或逗号隔开,而应该用一个细小的空格隔开。用垂直线分隔单元格几乎无法阅读:我过去常说垂直线对读者来说是障碍。

这是您的表格的另一个版本:

\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}

在此处输入图片描述


这是提供数据的完整版本;请注意,标题被分成两行,因为它们无法只容纳一行。唯一预定义的宽度在最后一列,其他的将占用它们所需的空间。

\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}

在此处输入图片描述

您可以考虑\addlinespace在行之间添加内容以将它们彼此分离:

\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}

在此处输入图片描述

相关内容