简体   繁体   中英

LaTex table over the width of the page

I am trying to replicate this table in Latex.

我要复制的表

However my tables always come out like this:

我的结果

My code:

\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}

The image you have added contains 6 different tables. In the following MWE, I have reproduced (approximate) the 1st table. You may reproduce all the tables in the same approach.

  • The package tabularx is necessary for the X type column. You can readthis Wikibook section for more information.
  • booktabs package is used for better horizontal lines. In the package documentation , you will find more about formal tables.
  • The package caption provides more control on placing captions in floating environments.
  • geometry package can be used to change page dimensions.

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}

输出

A sketch of my suggestion:

\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}

输出截图

I added the command \\sffamily to output the individual table in sans-serif-font.

The command \\par is to manually add a line-break within a column of type p ( paragraph ).

If your table exceeds the height of the page instead, you can check the package longtable , that you can anyway combine with booktabs .

You can change the parameters of the table, for example, use: P, m, etc. to specify the width of the table. Or use a relatively new table macro package (tabularray),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM