
我之前使用的是 3 列。我切換到兩列,格式化所有內容以適應,然後桌子壞了。
我找不到解決方法,有人可以幫我找到並解決問題嗎?
最小可重複範例(與背面編譯):
\documentclass{article}
\usepackage{caption}
\usepackage{float}
\usepackage{array}
\newcolumntype{L}[1]{>{\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\renewcommand\arraystretch{1.5}
\author{mikyll}
\title{test}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[H]
\centering
\begin{tabular}{ |p{0.2\linewidth}|p{0.7\linewidth}| }
\hline
\centering{\textbf{Feature}} & \centering{\textbf{Description}}\\
\hline
CORS control & test\\
\hline
Rate Limiting & test \\
\hline
\end{tabular}
\caption{API Gateway Requirements.}
\label{tab:api-gateway-requirements}
\end{table}
\end{document}
結果:
錯誤:
31: Misplaced \noalign
32: Extra alignment tab has been changed to \cr.
答案1
該指令會\centering{\textbf{Description}}
建立錯誤訊息。由於我看不出想要將標題單元格的內容居中的充分理由,因此我將刪除這些\centering
指令。 (如果由於某種原因,您只需將右側標題單元格的內容居中,只需將其替換\textbf{Description}
為\multicolumn{1}{c|}{\textbf{Description}}
.
我也會切換到tabularx
設定並將表格的目標寬度設為\textwidth
.
\documentclass{article}
\usepackage{tabularx,ragged2e}
\usepackage{caption}
\begin{document}
\begin{table}[htb]
\setlength\extrarowheight{2pt} % for a less-cramped look
\begin{tabularx}{\textwidth}{ |
>{\RaggedRight}p{0.2\linewidth} | % suppress full justification
>{\RaggedRight}X | } % suppress full justification
\hline
\textbf{Feature} & \textbf{Description} \\
\hline
CORS control & test \\
\hline
Rate Limiting & test \\
\hline
\end{tabularx}
\caption{API Gateway Requirements.}
\label{tab:api-gateway-requirements}
\end{table}
\end{document}