我有一张表定义如下:
\begin{tabular}{|c|c|c|}
\hline
\textbf{Library} & \textbf{Problem Type} & \textbf{Dependencies}\\
\hline
OSI & Abstract class for other libraries & CoinUtils, BuildTools\\
\hline
CLP & Linear Programming (LP) & Osi, CoinUtils, BuildTools\\
\hline
CBC & Mixed Integer LP & Cgl, Clp, Osi, CoinUtils, BuildTools\\
\hline
Symphony & Mixed Integer LP & Cgl, Clp, Osi, CoinUtils, BuildTools\\
\hline
Ipopt & Nonlinear programming (NLP) & BuildTools, Lapack, Blas, Mumps\\
\hline
Bonmin & Mixed Integer NLP & Ipopt, Cbc, Cgl, Clp, Osi, CoinUtils, BuildTools, Lapack, Blas, Mumps\\
\hline
\end{tabular}
最后一列太大,无法容纳所有行。如何修改它,以便这些单元格占据多行?
答案1
您可以使用tabularx
使表格适合线宽:
\documentclass{article}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\begin{document}
\begin{table}
\setlength{\extrarowheight}{2pt}
\begin{tabularx}{\linewidth}{|c|>{\RaggedRight\arraybackslash}X|>{\raggedright\arraybackslash}X|}
\hline
\textbf{Library} & \textbf{Problem Type} & \textbf{Dependencies}\\
\hline
OSI & Abstract class for other libraries & CoinUtils, BuildTools\\
\hline
CLP & Linear Programming (LP) & Osi, CoinUtils, BuildTools\\
\hline
CBC & Mixed Integer LP & Cgl, Clp, Osi, CoinUtils, BuildTools\\
\hline
Symphony & Mixed Integer LP & Cgl, Clp, Osi, CoinUtils, BuildTools\\
\hline
Ipopt & Nonlinear programming (NLP) & BuildTools, Lapack, Blas, Mumps\\
\hline
Bonmin & Mixed Integer NLP & Ipopt, Cbc, Cgl, Clp, Osi, CoinUtils, BuildTools, Lapack, Blas, Mumps\\
\hline
\end{tabularx}
\end{table}
\end{document}
答案2
这是另一个tabularx
基于 的解决方案。其整体结构与@Bernard 的非常相似回答;第三列启用了自动换行。主要区别在于它试图通过省略所有垂直线和大多数水平线来创建更加开放的“外观”。其余三条水平线由包提供的宏绘制booktabs
。
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{} l l L @{}}
\toprule
Library & Problem Type & Dependencies \\
\midrule
OSI & Abstract class for other libraries
& CoinUtils, BuildTools\\
\addlinespace
CLP & Linear Programming (LP)
& Osi, CoinUtils, BuildTools\\
\addlinespace
CBC & Mixed Integer LP
& Cgl, Clp, Osi, CoinUtils, BuildTools\\
\addlinespace
Symphony & Mixed Integer LP
& Cgl, Clp, Osi, CoinUtils, BuildTools\\
\addlinespace
Ipopt & Nonlinear programming (NLP)
& BuildTools, Lapack, Blas, Mumps\\
\addlinespace
Bonmin & Mixed Integer NLP
& Ipopt, Cbc, Cgl, Clp, Osi, CoinUtils, BuildTools, Lapack, Blas, Mumps\\
\bottomrule
\end{tabularx}
\end{document}