我使用生成表格网页https://www.tablesgenerator.com/但它显示undefined control sequence } after \end{tabular}%.
我尝试删除它,但结果出现了更多错误。你对如何解决此错误有什么建议吗?
谢谢
\begin{table}[hbt!]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
\multicolumn{1}{|c|}{\multirow{\textbf{Parameter}}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.4}$Zr$_{0.6}$NiSn}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.5}$Zr$_{0.5}$NiSn}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.6}$Zr$_{0.4}$NiSn}} \\ \cline{2-7}
\multicolumn{1}{|c|}{} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} \\ \hline
\textbf{Ti} & 15.13 & 3.20 & 18.20 & 3.13 & 15.13 & 3.20 \\ \hline
\textbf{Zr} & 20.89 & 3.84 & 18.62 & 3.85 & 20.89 & 3.84 \\ \hline
\textbf{Ni} & 31.53 & 3.17 & 30.76 & 3.17 & 31.53 & 3.17 \\ \hline
\textbf{Sn} & 32.44 & 3.05 & 32.42 & 3.04 & 32.44 & 3.05 \\ \hline
\textbf{Stoickhiometry} & \multicolumn{2}{c|}{\textbf{Ti$_{0.45}$Zr$_{0.64}$Ni$_{0.94}$Sn$_{0.97}$}} & \multicolumn{2}{c|}{\textbf{Ti$_{0.55}$Zr$_{0.56}$Ni$_{0.92} $Sn$_{0.97}$}} & \multicolumn{2}{c|}{\textbf{Ti$ _{0.57} $Zr$ _{0.48} $Ni$ _{0.98} $Sn$ _{0.96}$}} \\ \hline
\textbf{Phase 1 ($\%$Area)} & \multicolumn{2}{c|}{Ti$ _{0.19} $Zr$ _{0.8} $Ni$ _{1.03} $Sn$ _{0.97} (79.15$\%$) $} & \multicolumn{2}{c|}{Ti$ _{0.32} $Zr$ _{0.68} $Ni$ _{1.03} $Sn$ _{0.98} $ (69.79$\%$)} & \multicolumn{2}{c|}{Ti$ _{0.38} $Zr$ _{0.61} $Ni$ _{1.07} $Sn$ _{0.94} $ (55.06$\%$)} \\ \hline
\textbf{Phase 2 ($\%$Area} & \multicolumn{2}{c|}{Ti$_{1.18} $Zr$ _{0.23} $Ni$ {_0.44} $Sn$ _{1.14} $ (20.85$\%$)} & \multicolumn{2}{c|}{Ti$_{1.03} $Zr$ _{0.25} $Ni$_ {0.34}$Sn$_{1.54} $(30.21$\%$)} & \multicolumn{2}{c|}{Ti$ _{1.45} $Zr$ _{0.27} $Ni$ _{0.16} $Sn$ _{1.12} $(44.94$\%$)} \\ \hline
\textbf{Grain size} & \multicolumn{2}{c|}{17.15$\mu$m} & \multicolumn{2}{c|}{25.77$\mu$m} & \multicolumn{2}{c|}{19.53$\mu$m} \\ \hline
\end{tabular}%
}
\end{table}
答案1
乍一看,这是一个与唯一的那个由@leandriis 发布。例如,它不使用大胆的,它不使用垂直规则,只使用少量但间距适当的水平规则(使用booktabs
包的宏),它使用\ce
宏(通过mhchem
包)输入化学公式,使用\SI
宏(通过siunitx
包)输入科学单位及其相关数量。
我的答案主要不同之处在于为标题材料提供了更多结构,并将与区域相关的信息拆分到单独的行上。它还使用了一个tabularx
列,以确保所有六个数据列的宽度相等。
\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters suitably
\usepackage{siunitx,booktabs,mhchem,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mc[1]{\multicolumn{2}{c}{#1}}
\newcommand\mx[1]{\multicolumn{2}{c@{}}{#1}} % for final col.
\begin{document}
\begin{table}
\setlength\tabcolsep{3pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{} l *{6}{C} @{}}
\toprule
Parameter & \multicolumn{6}{c@{}}{As cast}\\
\cmidrule(l){2-7}
&\mc{\ce{Ti_{0.4}Zr_{0.6}NiSn}}
&\mc{\ce{Ti_{0.5}Zr_{0.5}NiSn}}
&\mx{\ce{Ti_{0.6}Zr_{0.4}NiSn}} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
& Atom & Rel.\ error
& Atom & Rel.\ error
& Atom & Rel.\ error \\
& (\%) & (\%, $1\sigma$)
& (\%) & (\%, $1\sigma$)
& (\%) & (\%, $1\sigma$) \\
\midrule
Ti & 15.13 & 3.20 & 18.20 & 3.13 & 15.13 & 3.20 \\ \addlinespace
Zr & 20.89 & 3.84 & 18.62 & 3.85 & 20.89 & 3.84 \\ \addlinespace
Ni & 31.53 & 3.17 & 30.76 & 3.17 & 31.53 & 3.17 \\ \addlinespace
Sn & 32.44 & 3.05 & 32.42 & 3.04 & 32.44 & 3.05 \\
\midrule
Stoichiometry
& \mc{\ce{Ti_{0.45}Zr_{0.64}Ni_{0.94}Sn_{0.97}}}
& \mc{\ce{Ti_{0.55}Zr_{0.56}Ni_{0.92}Sn_{0.97}}}
& \mx{\ce{Ti_{0.57}Zr_{0.48}Ni_{0.98}Sn_{0.96}}} \\
\addlinespace
Phase 1
& \mc{\ce{Ti_{0.19}Zr_{0.8}Ni_{1.03}Sn_{0.97}}}
& \mc{\ce{Ti_{0.32}Zr_{0.68}Ni_{1.03}Sn_{0.98}}}
& \mx{\ce{Ti_{0.38}Zr_{0.61}Ni_{1.07}Sn_{0.94}}} \\
\% Area & \mc{79.15\%} & \mc{69.79\%} & \mc{55.06\%}\\
\addlinespace
Phase 2
& \mc{\ce{Ti_{1.18}Zr_{0.23}Ni_{0.44}Sn_{1.14}}}
& \mc{\ce{Ti_{1.03}Zr_{0.25}Ni_{0.34}Sn_{1.54}}}
& \mx{\ce{Ti_{1.45}Zr_{0.27}Ni_{0.16}Sn_{1.12}}}\\
\% Area & \mc{20.85\%} & \mc{30.21\%} & \mc{44.94\%}\\
\addlinespace
Grain size
& \mc{\SI{17.15}{\micro\meter}}
& \mc{\SI{25.77}{\micro\meter}}
& \mx{\SI{19.53}{\micro\meter}} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
为了使您的代码可编译,我添加了graphicx
和multirow
包。我还纠正了命令的错误使用\multirow
,即缺少前两个参数\multirow{<number of rows>}{<width>}{<content>}
::
\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{multirow}
\begin{document}
\begin{table}[hbt!]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
\multicolumn{1}{|c|}{\multirow{3}{*}{\textbf{Parameter}}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.4}$Zr$_{0.6}$NiSn}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.5}$Zr$_{0.5}$NiSn}} & \multicolumn{2}{c|}{\textbf{As cast Ti$_{0.6}$Zr$_{0.4}$NiSn}} \\ \cline{2-7}
\multicolumn{1}{|c|}{} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} & \textbf{Atom ($\%$)} & \textbf{\begin{tabular}[c]{@{}c@{}}Rel. error ($\%$) \\ (1 sigma)\end{tabular}} \\ \hline
\textbf{Ti} & 15.13 & 3.20 & 18.20 & 3.13 & 15.13 & 3.20 \\ \hline
\textbf{Zr} & 20.89 & 3.84 & 18.62 & 3.85 & 20.89 & 3.84 \\ \hline
\textbf{Ni} & 31.53 & 3.17 & 30.76 & 3.17 & 31.53 & 3.17 \\ \hline
\textbf{Sn} & 32.44 & 3.05 & 32.42 & 3.04 & 32.44 & 3.05 \\ \hline
\textbf{Stoickhiometry} & \multicolumn{2}{c|}{\textbf{Ti$_{0.45}$Zr$_{0.64}$Ni$_{0.94}$Sn$_{0.97}$}} & \multicolumn{2}{c|}{\textbf{Ti$_{0.55}$Zr$_{0.56}$Ni$_{0.92} $Sn$_{0.97}$}} & \multicolumn{2}{c|}{\textbf{Ti$ _{0.57} $Zr$ _{0.48} $Ni$ _{0.98} $Sn$ _{0.96}$}} \\ \hline
\textbf{Phase 1 ($\%$Area)} & \multicolumn{2}{c|}{Ti$ _{0.19} $Zr$ _{0.8} $Ni$ _{1.03} $Sn$ _{0.97} (79.15$\%$) $} & \multicolumn{2}{c|}{Ti$ _{0.32} $Zr$ _{0.68} $Ni$ _{1.03} $Sn$ _{0.98} $ (69.79$\%$)} & \multicolumn{2}{c|}{Ti$ _{0.38} $Zr$ _{0.61} $Ni$ _{1.07} $Sn$ _{0.94} $ (55.06$\%$)} \\ \hline
\textbf{Phase 2 ($\%$Area} & \multicolumn{2}{c|}{Ti$_{1.18} $Zr$ _{0.23} $Ni$ {_0.44} $Sn$ _{1.14} $ (20.85$\%$)} & \multicolumn{2}{c|}{Ti$_{1.03} $Zr$ _{0.25} $Ni$_ {0.34}$Sn$_{1.54} $(30.21$\%$)} & \multicolumn{2}{c|}{Ti$ _{1.45} $Zr$ _{0.27} $Ni$ _{0.16} $Sn$ _{1.12} $(44.94$\%$)} \\ \hline
\textbf{Grain size} & \multicolumn{2}{c|}{17.15$\mu$m} & \multicolumn{2}{c|}{25.77$\mu$m} & \multicolumn{2}{c|}{19.53$\mu$m} \\ \hline
\end{tabular}%
}
\end{table}
\end{document}
但是,有很多方法可以改善表格的外观。首先,不要使用resizebox
来使表格适合文本宽度,因为这会导致字体大小不一致(有时小得难以辨认)。相反,你可以将字体大小更改为\small
并减少列之间的水平空间\setlength{\tabcolsep}{4.5pt}
(默认值为 6pt)。我还在“阶段 1”和“阶段 2”行中引入了换行符,以节省更多水平空间。
booktabs
为了使表格不那么拥挤,我建议删除所有垂直线,并根据包中的规则或仅使用一些垂直空白替换水平线。此外,我还删除了表格中的所有粗体。
为了改进化学元素和下标数字的排版,我使用了mhchem
包及其\ce
命令代替数学模式。最后,我还介绍了siunitx
在最后一行表格中添加单位的包(并删除了一些拼写错误):
\documentclass{article}
\usepackage{geometry}
\usepackage[version=4]{mhchem}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[hbt!]
\centering \small \setlength{\tabcolsep}{4.5pt}
\begin{tabular}{lcccccc}
\toprule
Parameter & \multicolumn{2}{c}{As cast \ce{Ti_{0.4}Zr_{0.6}NiSn}} & \multicolumn{2}{c}{As cast \ce{Ti_{0.5}Zr_{0.5}NiSn}} & \multicolumn{2}{c}{As cast \ce{Ti_{0.6}Zr_{0.4}NiSn}} \\
\cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
& Atom (\%) & Rel. error (\%) & Atom ($\%$) & Rel. error (\%) & Atom (\%) & Rel. error ($\%$) \\
& & (1 sigma) & & (1 sigma) & & (1 sigma) \\
\midrule
Ti & 15.13 & 3.20 & 18.20 & 3.13 & 15.13 & 3.20 \\
Zr & 20.89 & 3.84 & 18.62 & 3.85 & 20.89 & 3.84 \\
Ni & 31.53 & 3.17 & 30.76 & 3.17 & 31.53 & 3.17 \\
Sn & 32.44 & 3.05 & 32.42 & 3.04 & 32.44 & 3.05 \\ \addlinespace
Stoichiometry & \multicolumn{2}{c}{\ce{Ti_{0.45}Zr_{0.64}Ni_{0.94}Sn_{0.97}}} & \multicolumn{2}{c}{\ce{Ti_{0.55}Zr_{0.56}Ni_{0.92} Sn_{0.97}}} & \multicolumn{2}{c}{\ce{Ti_{0.57}Zr_{0.48}Ni_{0.98}Sn_{0.96}}} \\
\addlinespace
Phase 1 (\% Area) & \multicolumn{2}{c}{\ce{Ti_{0.19}Zr_{0.8}Ni_{1.03}Sn_{0.97}}} & \multicolumn{2}{c}{\ce{Ti_{0.32}Zr_{0.68}Ni_{1.03}Sn_{0.98}}} & \multicolumn{2}{c}{\ce{Ti_{0.38}Zr_{0.61}Ni_{1.07}Sn_{0.94}}} \\
& \multicolumn{2}{c}{(79.15\%)} & \multicolumn{2}{c}{(69.79\%)} & \multicolumn{2}{c}{(55.06\%)} \\
\addlinespace
Phase 2 (\%Area & \multicolumn{2}{c}{\ce{Ti_{1.18}Zr_{0.23}Ni_{0.44}Sn_{1.14}}} & \multicolumn{2}{c}{\ce{Ti_{1.03}Zr_{0.25}Ni_{0.34}Sn_{1.54}}} & \multicolumn{2}{c}{\ce{Ti_{1.45}Zr_{0.27}Ni_{0.16}Sn_{1.12}}} \\
Phase 2 (\%Area & \multicolumn{2}{c}{(20.85\%)} & \multicolumn{2}{c}{(30.21\%)} & \multicolumn{2}{c}{(44.94\%)} \\ \addlinespace
Grain size & \multicolumn{2}{c}{\SI{17.15}{\micro\meter}} & \multicolumn{2}{c}{\SI{25.77}{\micro\meter}} & \multicolumn{2}{c}{\SI{19.53}{\micro\meter}} \\ \bottomrule
\end{tabular}%
\end{table}
\end{document}
答案3
您不应\adjustbox
与表格一起使用,以避免字体大小不一致。我建议使用较小的字体大小,减少列间距并加载以获得更合适的边距(如果您不使用边注)。我使用和包geometry
添加了一些改进和代码简化。不需要多行。makecell
siunitx
chemformula
\documentclass[12pt]{report}
\usepackage{geometry}
\usepackage{makecell}
\renewcommand{\theadset} {\bfseries}
\usepackage{siunitx}
\usepackage{chemformula}
\begin{document}
\begin{table}[hbt!]
\centering
\footnotesize
\setlength{\tabcolsep}{2.5pt}
\setcellgapes{4pt}\makegapedcells
\begin{tabular}{|>{\bfseries}l|c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{6}{c}{\bfseries As cast} \\[1ex]
\multicolumn{1}{c}{} & \multicolumn{2}{c}{\bfseries \ch{Ti_{0.6}Zr_{0.5}NiSn}} & \multicolumn{2}{c}{\bfseries\ch{Ti_{0.5}Zr_{0.5}NiSn}} & \multicolumn{2}{c}{\bfseries\ch{Ti_{0.6}Zr_{0.4}NiSn}} \\ \cline{2-7}
\hline
\thead[l]{Parameter} & \thead{Atom \\(\%)} & \thead{Rel. error \\(\%) (1 sigma)} & \thead{Atom \\(\%)} & \thead{Rel. error\\ (\%) (1 sigma)} & \thead{Atom \\(\%)} & \thead{Rel. error \\($\%$) (1 sigma)} \\
\hline
Ti & 15.13 & 3.20 & 18.20 & 3.13 & 15.13 & 3.20 \\
\hline
Zr & 20.89 & 3.84 & 18.62 & 3.85 & 20.89 & 3.84 \\
\hline
Ni & 31.53 & 3.17 & 30.76 & 3.17 & 31.53 & 3.17 \\
\hline
Sn & 32.44 & 3.05 & 32.42 & 3.04 & 32.44 & 3.05 \\
\hline
Stoichiometry & \multicolumn{2}{c|}{\bfseries\ch{Ti_{0.45}Zr_{0.64}Ni_{0.94} Sn_{0.97}}} & \multicolumn{2}{c|}{\bfseries\ch{Ti_{0.55}Zr_{0.56}Ni_{0.92} Sn_{0.97}}} & \multicolumn{2}{c|}{\bfseries\ch{Ti_{0.57}Zr_{0.48}Ni_{0.98} Sn_{0.96}}} \\
\hline
\thead[l]{Phase 1 \\(\% Area)} & \multicolumn{2}{c|}{\makecell{\ch{Ti_{0.19}Zr_{0.8}Ni_{1.03} Sn_{0.97}}\\[0.5ex] (79.15\,\%) }} & \multicolumn{2}{c|}{\makecell{ \ch{Ti_{0.32}Zr_{0.68}Ni_{1.03} Sn_{0.98}}\\[0.5ex] (69.79\,\%)}} & \multicolumn{2}{c|}{\makecell{\ch{Ti_{0.38}Zr_{0.61}Ni_{1.07} Sn_{0.94}}\\[0.5ex] (55.06\,\%)}} \\
\hline
\thead[l]{Phase 2\\ (\% Area)} & \multicolumn{2}{c|}{\makecell{\ch{Ti_{1.18}Zr_{0.23}Ni_{0.44} Sn_{1.14}}\\[0.5ex] (20.85\,\,\%)}} & \multicolumn{2}{c|}{\makecell{\ch{Ti_{1.03}Zr_{0.25}Ni_{0.34} Sn_{1.54}}\\[0.5ex] (30.21\,\%)}} & \multicolumn{2}{c|}{\makecell{\ch{Ti_{1.45}Zr_{0.27}Ni_{0.16} Sn_{1.12}}\\[0.5ex] (44.94\,\%)}} \\
\hline
Grain size & \multicolumn{2}{c|}{\SI{17.15}{\um}} & \multicolumn{2}{c|}{\SI{25.77}{\um}} & \multicolumn{2}{c|}{\SI{19.53}{\um}} \\
\hline
\end{tabular}%
\end{table}
\end{document}