我正在尝试使用,\tabular
但我得到的表格的顶行高度不同,右侧有一个奇怪的间隙。请帮忙?
\begin{center}
\begin{tabular}{ |c|c| }
\hline
& \textbf{Power output loss per year}&\textbf{Type of solar cell}\\
\hline
Amorphous silicon (a-Si) & 0.87\\
\hline
Cadmium telluride (CdTe) & 0.4\\
\hline
Copper indium gallium selenide (CIGS) & 0.96\\
\hline
Monocrystalline silicon (mono-Si) & 0.36\\
\hline
Polycrystalline silicon (poly-Si) & 0.64\\
\hline
\end{tabular}
\end{center}
答案1
以下 MWE 包含您的表格的更正代码:
\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
\textbf{Type of solar cell} & \textbf{Power output loss per year}\\
\hline
Amorphous silicon (a-Si) & 0.87\\
\hline
Cadmium telluride (CdTe) & 0.4\\
\hline
Copper indium gallium selenide (CIGS) & 0.96\\
\hline
Monocrystalline silicon (mono-Si) & 0.36\\
\hline
Polycrystalline silicon (poly-Si) & 0.64\\
\hline
\end{tabular}
\end{center}
\end{document}
请注意,我不建议使用那么多水平线和垂直线来分隔单元格。相反,您可以使用类似以下 MWE 中的表格:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{cc}
\textbf{Type of solar cell} & \textbf{Power output loss per year}\\
\toprule
Amorphous silicon (a-Si) & 0.87\\
Cadmium telluride (CdTe) & 0.4\\
Copper indium gallium selenide (CIGS) & 0.96\\
Monocrystalline silicon (mono-Si) & 0.36\\
Polycrystalline silicon (poly-Si) & 0.64\\
\end{tabular}
\end{document}
答案2
以下还有两种改进的可能性:
\documentclass{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\begin{document}
\begin{table}[!htb]
\caption{Some caption}
\label{solar}
\sisetup{table-format = 1.2, table-number-alignment = center}
\setcellgapes{2pt}\makegapedcells
\centering
\begin{tabular}{lS}
\toprule
\thead{Type of solar cell} & {\thead{Power output loss \\ per year}}\\
\midrule
Amorphous silicon (a-Si) & 0.87 \\
Cadmium telluride (CdTe) & 0.4 \\
Copper indium gallium selenide (CIGS) & 0.96 \\
Monocrystalline silicon (mono-Si) & 0.36 \\
Polycrystalline silicon (poly-Si) & 0.64 \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[!htb]
\caption{Some caption}
\label{solar}
\sisetup{table-format = 1.2, table-number-alignment = center}
\setlength{\extrarowheight}{2pt}
\centering
\rowcolors{1}{white}{Gainsboro!60}
\begin{tabular}{lS}
\toprule
\thead{Type of solar cell} & {\thead{Power output loss \\ per year}}\\
\specialrule{\lightrulewidth}{\aboverulesep}{0pt}
Amorphous silicon (a-Si) & 0.87 \\
Cadmium telluride (CdTe) & 0.4 \\
Copper indium gallium selenide (CIGS) & 0.96 \\
Monocrystalline silicon (mono-Si) & 0.36 \\
Polycrystalline silicon (poly-Si) & 0.64 \\
\specialrule{\heavyrulewidth}{0pt}{0pt}
\end{tabular}
\end{table}
\end{document}