我怎样才能制作一张有两列表格的表格?

我怎样才能制作一张有两列表格的表格?

我想制作一个两列表格,其列标题为超参数和最佳值。

我写了这段代码:

\begin{table}[H]
  \begin{center}
    \caption{More columns.}
    \label{tab:table1}
    \begin{tabular}{|c|c|}
      \textbf{Hyperparameter} & \textbf{Optimal Value}\\
      \hline
      base_estimator__C & 1.0 \\ 
      base_estimator__decision_function_shape & ovo\\ 
      base_estimator__kernel & Linear\\ 
    \end{tabular}
  \end{center}
\end{table}

它不起作用,出现多个错误。

答案1

在此处输入图片描述

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=1.00cm]{geometry}
\begin{document}
    \begin{table}
        \begin{center}
            \caption{More columns.}
            \label{tab:table1}
            \begin{tabular}{|c|c|}
                \textbf{Hyperparameter} & \textbf{Optimal Value}\\
                \hline
                base\_estimator\_C & 1.0 \\ 
                base\_estimator\_decision\_function\_shape & ovo\\ 
                base\_estimator\_kernel & Linear\\ 
            \end{tabular}
        \end{center}
    \end{table}
\end{document}

编辑

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\begin{document}
    \begin{table}
        \begin{center}
            \caption{More columns.}
            \label{tab:table1}
            \begin{tabular}{cc}\toprule
                \textbf{Hyperparameter} & \textbf{Optimal Value}\\
                \midrule
                base\_estimator\_C & 1.0 \\ 
                base\_estimator\_decision\_function\_shape & ovo\\ 
                base\_estimator\_kernel & Linear\\ 
                \bottomrule
            \end{tabular}
        \end{center}
    \end{table}
\end{document}

在此处输入图片描述

答案2

以下是两个替代示例:

\documentclass[10pt,a4paper]{article}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{collcell}
\newcommand{\myverbatim}[1]{\ttfamily\detokenize{#1}}

\begin{document}
    \begin{table}
        \centering
            \caption{More columns.}
            \label{tab:table1}
            \begin{tabular}{>{\collectcell\myverbatim}l<{\endcollectcell}c}\toprule
                \multicolumn{1}{l}{\textbf{Hyperparameter}} & \textbf{Optimal Value}\\
                \midrule
                base_estimator_C & 1.0 \\ 
                base_estimator_decision_function_shape & ovo\\ 
                base_estimator_kernel & Linear\\ 
                \bottomrule
            \end{tabular}
    \end{table}
\end{document}

在此处输入图片描述


\documentclass[10pt,a4paper]{article}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{underscore}

\begin{document}
    \begin{table}
        \centering
            \caption{More columns.}
            \label{tab:table1}
            \begin{tabular}{lc}\toprule
                \textbf{Hyperparameter} & \textbf{Optimal Value}\\
                \midrule
                base_estimator_C & 1.0 \\ 
                base_estimator_decision_function_shape & ovo\\ 
                base_estimator_kernel & Linear\\ 
                \bottomrule
            \end{tabular}
    \end{table}
\end{document}

在此处输入图片描述

相关内容