考虑以下代码:
\documentclass{article}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc} % use 8-bit T1 fonts
\usepackage{hyperref} % hyperlinks
\usepackage{url} % simple URL typesetting
\usepackage{booktabs} % professional-quality tables
\usepackage{amsfonts} % blackboard math symbols
\usepackage{nicefrac} % compact symbols for 1/2, etc.
\usepackage{microtype} % microtypography
\usepackage{lipsum}
\usepackage{fancyhdr} % header
\usepackage[pdftex]{graphicx}
\usepackage{graphics}
\usepackage{epstopdf}
\usepackage{float}
\usepackage{tikz}
%\usepackage{color}
\usepackage{pdfpages}
\usepackage{hhline}
\usepackage[labelfont=bf]{caption}
\usepackage{colortbl}
\usepackage{caption}
\captionsetup[table]{skip=10pt}
%\usepackage[table]{xcolor}
\graphicspath{{media}} % organize your images and other figures under media/ folder
\usepackage[english]{babel}
\usepackage[backend=bibtex]{biblatex}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{l|l|l}
\hhline{|===|}
Operation / List & Singly-linked list & Doubly-linked list \\
\hline
\texttt{prepend} & $\Theta(1)$ & $\Theta(1)$ \\
\texttt{append} & $\Theta(1)$ & $\Theta(1)$ \\
\texttt{insert$(i)$} & $\Theta(i) = \mathcal{O}(N)$ & $\Theta(\min(i, N - i)) = \mathcal{O}(N)$ \\
\hline
\texttt{get$(i)$} & $\Theta(i)$ & $\Theta(\min(i, N - i))$ \\
\hline
\texttt{removeHead} & $\Theta(1)$ & $\Theta(1)$ \\
\texttt{removeTail} & $\Theta(N)$ & $\Theta(1)$ \\
\texttt{removeAt($i$)} & $\Theta(i) = \mathcal{O}(N)$ & $\Theta(\min (i, N - i)) = \mathcal{O}(N)$ \\
\hline
\texttt{prependCollection} & $\Theta(M)$ & $\Theta(M)$ \\
\texttt{appendCollection} & $\Theta(M)$ & $\Theta(M)$ \\
\texttt{insertCollection} & $\Theta(i + M) = \mathcal{O}(N) + \Theta(M)$ & $\Theta(\min (i, N - i) + M) = \mathcal{O}(N) + \Theta(M)$ \\
\hline
\texttt{removeRange$(b, e)$} & $\Theta(b + M) = \mathcal{O}(N) + \Theta
(M)$ & $\Theta(b + M) = \mathcal{O}(N) + \Theta(M)$ \\
\hhline{|===|}
\label{tbl:linked_lists}
\end{tabular}
\end{table}
\end{document}
编译后,它给我:
我怎样才能解决这个问题?
答案1
正如@egreg 在评论中已经指出的那样,您可以通过将指令从环境\label
中取出来解决当前的印刷问题tabular
。
此外,您可能还希望(a)通过赋予表格更开放的“外观”使其外观更具吸引力,以及(b)tabular
通过自动执行在第 1 列中切换到等宽字体以及在第 2 列和第 3 列中切换到内联数学模式的任务,减少环境中的一些代码混乱。
\documentclass{article}
%% (I've tried to simplify the preamble down to the bare minimum)
\usepackage{caption}
\captionsetup{skip=0.5\baselineskip,labelfont=bf}
%% new:
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters suitably
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{L}{>{$}l<{$}} % left-aligned, automatic math model
\usepackage{booktabs} % for well-spaced horizontal rules
\begin{document}
\begin{table}[ht] % please not "[H]"
\centering
\caption{xyz}
\label{tbl:linked_lists}
\begin{tabular}{@{} >{\ttfamily}l L L @{}}
\toprule
\multicolumn{1}{@{}l}{Operation\slash List} &
\multicolumn{1}{l}{Singly-linked list} &
\multicolumn{1}{l}{Doubly-linked list} \\
\midrule
prepend & \Theta(1) & \Theta(1) \\
append & \Theta(1) & \Theta(1) \\
insert(i) & \Theta(i) = \mathcal{O}(N)
& \Theta(\min(i, N - i)) = \mathcal{O}(N) \\
\addlinespace
get(i) & \Theta(i) & \Theta(\min(i, N - i)) \\
\addlinespace
removeHead & \Theta(1) & \Theta(1) \\
removeTail & \Theta(N) & \Theta(1) \\
removeAt(i) & \Theta(i) = \mathcal{O}(N)
& \Theta(\min (i, N - i)) = \mathcal{O}(N) \\
\addlinespace
prependCollection & \Theta(M) & \Theta(M) \\
appendCollection & \Theta(M) & \Theta(M) \\
insertCollection & \Theta(i + M) = \mathcal{O}(N) + \Theta(M)
& \Theta(\min (i, N - i) + M) = \mathcal{O}(N) + \Theta(M) \\
\addlinespace
removeRange(b,e) & \Theta(b + M) = \mathcal{O}(N) + \Theta (M)
& \Theta(b + M) = \mathcal{O}(N) + \Theta(M) \\
\bottomrule
\end{tabular}
\end{table}
\end{document}