我的桌子上有两条不应该存在的垂直线。它看起来像这样:
| |
Table 1: Title
这是我的代码的开头:
\renewcommand{\arraystretch}{1.2}
\begin{table}[h!]
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} \\
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
\hline \hline
我该如何删除这两条垂直线?
答案1
消除不需要的竖线对的最简单的解决方案是删除\\
紧随其后的指令\begin{tabular}{...}
。
一个更好的——当然更优雅的——解决方案来自于认识到你目前似乎没有使用 LaTeX 的\caption
命令来生成标题。而不是输入
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
你真的应该写
\caption{Efficiency Analysis}
让 LaTeX 负责计算表格编号等工作。如果您需要将标题排版为粗体,只需使用选项加载包caption
即可text=bf
。加载caption
包还将导致在标题和材料之间插入一些垂直空白tabular
,从而在视觉上分离两个元素。
\documentclass{article}
\usepackage[margin=1in]{geometry} % set margins to suit your needs
\usepackage{array,ragged2e}
\usepackage[font=bf]{caption}
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}
\begin{document}
Original version, with unwanted pair of vertical bars
\begin{table}[ht!]
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} \\
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
\hline \hline
a & b & c & d
\end{tabular}
\end{table}
\bigskip
Simple modification: Remove the first \verb+\\+ directive
\begin{table}[ht!]
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|}
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
\hline \hline
a & b & c & d
\end{tabular}
\end{table}
\bigskip
Better modification: Use the \verb+\caption+ command (\emph{and} still remove the first \verb+\\+ directive)
\setcounter{table}{6} % just for this example
\begin{table}[ht!]
\caption{Efficiency Analysis}
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|}
\hline \hline
a & b & c & d
\end{tabular}
\end{table}
\end{document}