【问题标题】:LaTex table over the width of the page页面宽度上的 LaTex 表格
【发布时间】:2021-12-26 02:30:36
【问题描述】:

我正在尝试在 Latex 中复制此表。

但是我的桌子总是这样:

我的代码:

\begin{center}
\begin{tabular}{c|c}
    \textbf{SQL} & \textbf{MONGODB} \\
    Database & Database \\
    Table & Collection \\
    Row & Document \\
    Column & Field \\
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
    &  \\
    \hline
\end{tabular}
\end{center}

【问题讨论】:

标签: latex tabular


【解决方案1】:

可以更改表格的参数,例如使用:pm等来指定表格的宽度。或者使用相对较新的表格宏包(tabularray)。

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}
    \centering
    \caption{Terminologies in SQL and ...}
    \begin{tabular}{m{6cm}m{6cm}}
    \toprule
    \textbf{SQL} & \textbf{MONGODB} \\
    \midrule
    Database & Database \\
    Table & Collection \\
    Row & Document \\
    Column & Field \\
    Primary key (specify any unique column or column combination as primary key) & Primary key (the primary key is automatically set to the \_id field in MongoDB)\\
    blah blah & blah blah \\
    \bottomrule
    \end{tabular}
\end{table}

\begin{tblr}{XX}
\toprule
    \textbf{SQL} & \textbf{MONGODB} \\
\midrule
    Database & Database \\
    Table & Collection \\
    Row & Document \\
    Column & Field \\
    Primary key (specify any unique column or column combination as primary key) & Primary key (the primary key is automatically set to the \_id field in MongoDB)\\
    blah blah & blah blah \\
\bottomrule
\end{tblr}
\end{document}

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

您添加的图像包含 6 个不同的表格。在下面的 MWE 中,我复制了(近似)第一个表。您可以用相同的方法复制所有表格。

  • tabularx 包是X 类型列所必需的。您可以阅读this Wikibook section 了解更多信息。
  • booktabs 包用于更好的水平线。在package documentation,您会发现更多关于正式表格的信息。
  • caption 提供了对在浮动环境中放置字幕的更多控制。
  • geometry 包可用于更改页面尺寸。

MWE:

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{geometry}

\begin{document}
\begin{table}
    \centering
    \caption{Terminologies in SQL and ...}
    \label{tab:my_label}
    \begin{tabularx}{\textwidth}{XX}
    \toprule
    \textbf{SQL} & \textbf{MONGODB} \\
    \midrule
    Database & Database \\
    Table & Collection \\
    Row & Document \\
    Column & Field \\
    Primary key (specify any unique column or column combination as primary key) & Primary key (the primary key is automatically set to the \_id field in MongoDB)\\
    blah blah & blah blah \\
    \bottomrule
    \end{tabularx}
    
\end{table}
\end{document}

【讨论】:

    【解决方案3】:

    我的建议草图:

    \documentclass{article}
    \usepackage{lipsum}
    \usepackage{tabularx,booktabs}
    
    \begin{document}
    \lipsum[4]
    
    \begin{table}[!ht]
    \sffamily
    \caption{Terminologies in SQL \& corresponding in MongoDB}
    \label{tab:my_label}
    \centering
    \begin{tabularx}{\textwidth}{*{2}{p{0.5\textwidth}}}
    \toprule
    \textbf{SQL} & \textbf{MongoDB}\\
    \midrule
    Database & Database\\
    \dots & \dots \\
    Primary key (specify any unique column or column combinations as primary key) & Primary key (the primary key is\par auto\-matically set to the \_id field\par in MongoDB)\\
    \dots & \dots \\
    \bottomrule
    \end{tabularx}
    \end{table}
    
    \lipsum[4]
    \end{document}
    

    我添加了命令\sffamily 以无衬线字体输出单个表格。

    命令\par 是在p 类型的列中手动添加换行符(段落)。

    如果您的表格超出了页面的高度,您可以检查包longtable,无论如何您都可以与booktabs 结合使用。

    【讨论】:

      猜你喜欢
      • 2012-02-18
      • 2010-12-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多