-1

I want to make a two column table whose column titles are Hyperparameter and Optimal Value.

I wrote this code:

\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}

It doesn't work, giving multiple errors.

leandriis
  • 62,593
Debbie
  • 303
  • 1
    add a backslash \ before the underscore and add package \usepackage[T1]{fontenc} -- also suggest use booktabs package and use toprule, midrule, bottomrule for better spacing as in the answer below -- also suggest remove vertical lines – js bibra Mar 16 '21 at 10:52
  • I removed the tabularx tag since you don't use this package in your code. Ragarding the error messags you should get upon trying to compile your code, you might want to take a look at: https://tex.stackexchange.com/a/554241/134144 – leandriis Mar 17 '21 at 08:54

2 Answers2

2

Here are two alternative examples:

\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}

enter image description here


\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}

enter image description here

leandriis
  • 62,593
1

enter image description here

\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}

edit

\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}

enter image description here

js bibra
  • 21,280