修复表格大小

修复表格大小

我希望我的表格位于中心并且文本仍然可读,位于我为其编写的代码下方,但正如您在屏幕截图上看到的那样,它不起作用。

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}[h]
\centering
\label{tab:methods}{
\begin{tabular}{c|l}   
\hline
\multicolumn{1}{c|}{\textbf{\textbf{Property/Method}}} & \textbf{Description} \\
\hline
\texttt{setItem()} & Adds a key-value pair to a Web Storage object. If the key already 
exists, its value is changed.\\
\hline
\texttt{getItem()} & Retrieves the value of a specified key from a Web Storage object. 
\\
\hline
\texttt{removeItem()} & Removes a specified key and the value associated with it from a 
Web Storage object.\\
\hline
\texttt{clear()} & Removes all the key-value pairs from the Web Storage object.\\
\hline
\texttt{key()} & Takes a zero-based index and returns key name at that index. \\
\hline
\texttt{length} & Returns the total number of key-value pairs from the Web Storage 
object. \\
\hline
\texttt{remainingSpace} & Returns the amount of storage space (in bytes) still available 
for storing data. This property is currently supported only by IE.\\
\hline
\end{tabular}
}
\caption{Properties and Methods of \textit{Session Storage} and \textit{Local Storage}}
\end{table}
\end{document}

''' 在此处输入图片描述

答案1

显然,右列太宽了;最明显的解决方案是使用允许换行的列说明符。如果没有软件包,您可以使用p{3.2in}或类似的代替l,但我建议使用 tabularx 软件包,这样您就可以使用X列说明符,它将扩展以使用剩余的宽度。

\documentclass{article}
\usepackage{tabularx}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}[h]
\centering
\label{tab:methods}{
\begin{tabularx}{\textwidth}{c|X}
\hline
\textbf{Property/Method} & \textbf{Description} \\
\hline
\texttt{setItem()} & Adds a key-value pair to a Web Storage object. If the key already 
exists, its value is changed.\\
\hline
\texttt{getItem()} & Retrieves the value of a specified key from a Web Storage object. 
\\
\hline
\texttt{removeItem()} & Removes a specified key and the value associated with it from a 
Web Storage object.\\
\hline
\texttt{clear()} & Removes all the key-value pairs from the Web Storage object.\\
\hline
\texttt{key()} & Takes a zero-based index and returns key name at that index. \\
\hline
\texttt{length} & Returns the total number of key-value pairs from the Web Storage 
object. \\
\hline
\texttt{remainingSpace} & Returns the amount of storage space (in bytes) still available 
for storing data. This property is currently supported only by IE.\\
\hline
\end{tabularx}
}
\caption{Properties and Methods of \textit{Session Storage} and \textit{Local Storage}}
\end{table}
\end{document}

tabularx 示例

相关内容