在多列表格中添加列

在多列表格中添加列

这是我的代码

\begin{tabular}{|c|c|}
\hline
Genre&Prénom\\\hline
Humain&Aragorn\\\hline
\multirow{4}{*}{Hobbit}&Frodon\\\cline{2-2}
&Sam\\\cline{2-2}
&Peregrin\\\cline{2-2}
&Meriadoc\\\hline
Elfe&Legolas\\\hline
\end{tabular}

我怎样才能添加像第二列一样的第三列?

答案1

我想向您展示针对您的表格的三种不同的解决方案:

表格.tex

\documentclass{article}

\usepackage{booktabs} % for nice lines
\usepackage{siunitx}  % nice numbers and units and 'S' in table
\usepackage{multirow} % enable \multirow command

\begin{document}
short answer to your question:\\
\begin{tabular}{|c|c|S|}
\hline
Genre & Name & {Weight}\\\hline
Humain & Aragorn & 102 \\\hline
\multirow{4}{*}{Hobbit}&Frodon & 32.1\\\cline{2-3}
    &Sam & 3.2 \\\cline{2-3}
    &Peregrin & 2.232\\\cline{2-3}
    &Meriadoc & 23 \\\hline
Elfe&Legolas & 34.5 \\\hline
\end{tabular}\\[1cm]

You can also use the power of booktabs and siunitx:\\
\begin{tabular}[ht]{l c S} % alignment l = left, c = centre, S = at decimal - needs siunitx
\toprule
Genre&Name& {Weight}\\  % protect non numbers with {} in S columns
\midrule
Elfe&Legolas & 34.5\\
Dwarf&Peter & 103.31\\
\bottomrule
\end{tabular}\\[1cm]

And combine that with your table:\\
\begin{tabular}{c c S}
\toprule
Genre & Name & {Weight}\\\midrule
Humain & Aragorn & 102 \\\midrule
\multirow{4}{*}{Hobbit}&Frodon & 32.1\\\cline{2-3}
    &Sam & 3.2 \\\cline{2-3}
    &Peregrin & 2.232\\\cline{2-3}
    &Meriadoc & 23 \\\midrule
Elfe&Legolas & 34.5 \\
\bottomrule
\end{tabular}

\end{document}

3 tables

相关内容