我是 LaTeX 新手,在用 LaTeX 编译上述所需表格时遇到了问题。这是我正在使用的代码:
\documentclass{article}
\usepackage{amsmath}
\title{Latex File}
\author{Noob}
\date{\today}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.2}
\begin{center}
\begin{tabular}{c c c c c c}
\hline
\hline
Nuclide & Gamma-Ray \newline Energy (keV) & Half-Life \newline (Days) & Master\newline Source \newline ($\gamma$ps/g) & This Source \newline ($\gamma$ps) & Calibration Method \\
\hline
\hline
$^{210}\text{Pb}$ & 46.5 & 8.145E3 & &4.596E2 & 4IILS \\
$^{242}\text{Am}$ & 59.5 & 1.580E5 & & 3.265E2 & 4IILS \\
$^{109}\text{Cd}$ & 88.0 & 4.626E2 & 1.665E5 & 4.408E2 & HPGe \\
$^{57}\text{Co}$ & 122.1 & 2.718E2 & 8.986E4 & 2.379E2 & HPGe \\
$^{139}\text{Ce}$ & 165.9 & 1.376E2 & 1.253E5 & 3.315E2 & HPGe \\
$^{51}\text{Cr}$ & 320.1 & 2.770E1 & 4.003E5 & 1.060E3 & IC \\
$^{113}\text{Sn}$ & 391.7 & 1.151E2 & 1.746E5 & 4.621E2 & HPGe \\
$^{85}\text{Sr}$ & 514.0 & 6.484E1 & 3.070E5 & 8.127E2 & IC \\
$^{137}\text{Cs}$ & 661.7 & 1.098E4 & 1.111E5 & 2.941E2 & HPGe \\
$^{88}\text{Y}$ & 898.0 & 1.066E2 & 4.263E5 & 1.128E3 & HPGe \\
$^{60}\text{Co}$ & 1173.2 & 1.925E3 & 2126E5 & 5.628E2 & HPGe \\
$^{60}\text{Co}$ & 1332.5 & 1.925E3 & 2.127E5 & 5.629E2 & HPGe \\
$^{88}\text{Y}$ & 1836.1 & 1.066E2 & 4.513E5 & 1.195E3 & HOGe \\
\hline
\end{tabular}
\end{center}
\end{document}
我遇到的问题是
- 该
\newline
命令没有执行任何操作, - 没有
\center
固定表格的方向,表格超出了页面范围。
答案1
以下是我排版表格的方式:
\documentclass{article}
\usepackage[margin = 4cm]{geometry} % to avoid `overfull \hbox' warning
\usepackage[tableposition = top]{caption}
\usepackage{mathtools}
\usepackage{siunitx}
\usepackage{booktabs}
%\usepackage[version = 4]{mhchem} % use if you have more than a few chemical symbols
\newcommand*\nuc[1]{$\prescript{#1}{}{}$}
\newcommand*\elem[1]{\textup{#1}}
\newcommand*\mc[1]{\multicolumn{2}{c}{#1}}
\newcommand*\lineB[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\begin{document}
\begin{table}
\centering
\caption{A table with some data.}
\label{tbl:some-data}
\begin{tabular}{
@{\hspace{0.85em}} r
@{\hspace{0em}} l
S[table-format = 4.1]
*{3}{S[table-format = 1.3e1, exponent-product = \cdot]}
c
}
\toprule
\mc{Nuclide} & {\lineB{Gamma-Ray\\ Energy}} & {Half-life} & {Master Source} & {This Source} & {\lineB{Calibration\\ Method}} \\[2ex]
\mc{---} & {\si{\keV}} & {Days} & {$\gamma$\si[per-mode = symbol]{\ps\per\g}} & {$\gamma$\si{\ps}} & --- \\
\midrule
\nuc{210} & \elem{Pb} & 46.5 & 8.145e3 & {---} & 4.596e2 & 4IILS \\
\nuc{242} & \elem{Am} & 59.5 & 1.580e5 & {---} & 3.265e2 & 4IILS \\
\nuc{109} & \elem{Cd} & 88.0 & 4.626e2 & 1.665e5 & 4.408e2 & HPGe \\
\nuc{57} & \elem{Co} & 122.1 & 2.718e2 & 8.986e4 & 2.379e2 & HPGe \\
\nuc{139} & \elem{Ce} & 165.9 & 1.376e2 & 1.253e5 & 3.315e2 & HPGe \\
\nuc{51} & \elem{Cr} & 320.1 & 2.770e1 & 4.003e5 & 1.060e3 & IC \\
\nuc{113} & \elem{Sn} & 391.7 & 1.151e2 & 1.746e5 & 4.621e2 & HPGe \\
\nuc{85} & \elem{Sr} & 514.0 & 6.484e1 & 3.070e5 & 8.127e2 & IC \\
\nuc{137} & \elem{Cs} & 661.7 & 1.098e4 & 1.111e5 & 2.941e2 & HPGe \\
\nuc{88} & \elem{Y} & 898.0 & 1.066e2 & 4.263e5 & 1.128e3 & HPGe \\
\nuc{60} & \elem{Co} & 1173.2 & 1.925e3 & 2.126e5 & 5.628e2 & HPGe \\
\nuc{60} & \elem{Y} & 1332.5 & 1.925e3 & 2.127e5 & 5.629e2 & HPGe \\
\nuc{88} & \elem{Y} & 1836.1 & 1.066e2 & 4.513e5 & 1.195e3 & HOGe \\
\bottomrule
\end{tabular}
\end{table}
\noindent Above we have table~\ref{tbl:some-data}.
\end{document}
一些建议:
答案2
\newline
在列类型内不起作用c
。您可以改用tabularx
及其X
列。
\documentclass{article}
\usepackage{amsmath,tabularx}
\title{Latex File}
\author{Noob}
\date{\today}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.2}
\noindent
\begin{tabularx}{\textwidth}{XXXXXX}
\hline
\hline
Nuclide & Gamma-Ray Energy (keV) & Half-Life (Days) & Master Source ($\gamma$ps/g) & This Source ($\gamma$ps) & Calibration Method \\
\hline
\hline
$^{210}\text{Pb}$ & 46.5 & 8.145E3 & &4.596E2 & 4IILS \\
$^{242}\text{Am}$ & 59.5 & 1.580E5 & & 3.265E2 & 4IILS \\
$^{109}\text{Cd}$ & 88.0 & 4.626E2 & 1.665E5 & 4.408E2 & HPGe \\
$^{57}\text{Co}$ & 122.1 & 2.718E2 & 8.986E4 & 2.379E2 & HPGe \\
$^{139}\text{Ce}$ & 165.9 & 1.376E2 & 1.253E5 & 3.315E2 & HPGe \\
$^{51}\text{Cr}$ & 320.1 & 2.770E1 & 4.003E5 & 1.060E3 & IC \\
$^{113}\text{Sn}$ & 391.7 & 1.151E2 & 1.746E5 & 4.621E2 & HPGe \\
$^{85}\text{Sr}$ & 514.0 & 6.484E1 & 3.070E5 & 8.127E2 & IC \\
$^{137}\text{Cs}$ & 661.7 & 1.098E4 & 1.111E5 & 2.941E2 & HPGe \\
$^{88}\text{Y}$ & 898.0 & 1.066E2 & 4.263E5 & 1.128E3 & HPGe \\
$^{60}\text{Co}$ & 1173.2 & 1.925E3 & 2126E5 & 5.628E2 & HPGe \\
$^{60}\text{Co}$ & 1332.5 & 1.925E3 & 2.127E5 & 5.629E2 & HPGe \\
$^{88}\text{Y}$ & 1836.1 & 1.066E2 & 4.513E5 & 1.195E3 & HOGe \\
\hline
\end{tabularx}
\end{document}
带有居中列和booktabs
规则:
\documentclass{article}
\usepackage{amsmath,tabularx,booktabs}
\title{Latex File}
\author{Noob}
\date{\today}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.2}
\noindent
\begin{tabularx}{\textwidth}{*{6}{>{\centering\arraybackslash}X}}
\toprule
Nuclide & Gamma-Ray Energy (keV) & Half-Life (Days) & Master Source ($\gamma$ps/g) & This Source ($\gamma$ps) & Calibration Method \\
\midrule
$^{210}\text{Pb}$ & 46.5 & 8.145E3 & &4.596E2 & 4IILS \\
$^{242}\text{Am}$ & 59.5 & 1.580E5 & & 3.265E2 & 4IILS \\
$^{109}\text{Cd}$ & 88.0 & 4.626E2 & 1.665E5 & 4.408E2 & HPGe \\
$^{57}\text{Co}$ & 122.1 & 2.718E2 & 8.986E4 & 2.379E2 & HPGe \\
$^{139}\text{Ce}$ & 165.9 & 1.376E2 & 1.253E5 & 3.315E2 & HPGe \\
$^{51}\text{Cr}$ & 320.1 & 2.770E1 & 4.003E5 & 1.060E3 & IC \\
$^{113}\text{Sn}$ & 391.7 & 1.151E2 & 1.746E5 & 4.621E2 & HPGe \\
$^{85}\text{Sr}$ & 514.0 & 6.484E1 & 3.070E5 & 8.127E2 & IC \\
$^{137}\text{Cs}$ & 661.7 & 1.098E4 & 1.111E5 & 2.941E2 & HPGe \\
$^{88}\text{Y}$ & 898.0 & 1.066E2 & 4.263E5 & 1.128E3 & HPGe \\
$^{60}\text{Co}$ & 1173.2 & 1.925E3 & 2126E5 & 5.628E2 & HPGe \\
$^{60}\text{Co}$ & 1332.5 & 1.925E3 & 2.127E5 & 5.629E2 & HPGe \\
$^{88}\text{Y}$ & 1836.1 & 1.066E2 & 4.513E5 & 1.195E3 & HOGe \\
\bottomrule
\end{tabularx}
\end{document}