mmithoefer
mmithoefer

Reputation: 23

LaTex table over the width of the page

I am trying to replicate this table in Latex.

the table I want to replicate

However my tables always come out like this:

my result

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}

Upvotes: 2

Views: 19194

Answers (3)

MattAllegro
MattAllegro

Reputation: 7345

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}

screenshot of output

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.

Upvotes: 1

1210
1210

Reputation: 21

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).

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

enter image description here

Upvotes: 2

Imran
Imran

Reputation: 385

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 read this 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}

output

Upvotes: 2

Related Questions