1

I'm writing a table that's too wide for the page, so I tried using a fixed width for the columns, but when I do that two columns merge into one:

enter image description here

And a MWE:

\documentclass[a4paper]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\begin{table}[]
\centering
\begin{tabular}{|r p{2cm} |c|c|}
\textbf{Quantidade de rodadas} & \textbf{Duração (ms)}&
\textbf{Controle no começo do jogo} \\
\hline
17 & 90110   & Monte Carlo \\
27 & 140253  & Monte Carlo \\
19 & 100284  & Monte Carlo \\
23 & 120247  & Monte Carlo \\
11 & 60366   & Monte Carlo \\
\end{tabular}
\caption{Durações das partidas} \label{montecarloduracoes}
\end{table}
\end{document}

Am I doing something wrong? Or do I have to use a different method to compress the table horizontally?

  • It seems your table has 3 columns but you're defining 4 columns in your header : \begin{tabular}{|r p{2cm} |c|c|} (Bernard's solution corrected it without mentioning) – Christoph Frings Jun 16 '16 at 7:31
  • @ChrisS and Mico : Yes you are right, it was more a comment than an answer, though OP asked "am I doing something wrong" and nobody pointed it out to him, unfortunately. I couldn't comment then, I can now. Story over, thx for your assistance. – Christoph Frings Jun 18 '16 at 19:18
1

You can do that with makecell, which allows for line breaks and a common formatting of cells introduced by the \thead or \makecell commands.

I replaced the abntex2 cls (not installed on my system) with report:

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{makecell} %
\usepackage{showframe}
\renewcommand\theadfont{\normalsize\bfseries}

\begin{document}
\vspace*{1cm}
\begin{table}[!ht]
  \centering\setlength\extrarowheight{3pt}
  \begin{tabular}{|r |c|c|}
    \hline
    \thead{Quantidade \\ de rodadas} & \thead{Duração\\ (ms)}&
    \thead{Controle no começo\\ do jogo} \\
    \hline
    17 & 90110 & Monte Carlo \\
    27 & 140253 & Monte Carlo \\
    19 & 100284 & Monte Carlo \\
    23 & 120247 & Monte Carlo \\
    11 & 60366 & Monte Carlo \\ \hline
  \end{tabular}
  \caption{Durações das partidas} \label{montecarloduracoes}
\end{table}

\end{document} 

enter image description here

| improve this answer | |
1

I suggest you give your table an "open" and easily-accessible look by getting rid of the vertical bars. To further ease the readability of the numbers in the middle column, consider aligning them on the (implicit) decimal marker.

enter image description here

\documentclass[a4paper]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{siunitx,array,booktabs,ragged2e}
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}
\begin{document}

\begin{table}
\centering
\begin{tabular}{C{2cm} S[table-format=6.0] C{3cm}}
\textbf{Quantidade de rodadas} & 
\multicolumn{1}{C{2cm}}{\textbf{Duração} (ms)}&
\textbf{Controle no começo do jogo} \\
\midrule
17 & 90110   & Monte Carlo \\
27 & 140253  & Monte Carlo \\
19 & 100284  & Monte Carlo \\
23 & 120247  & Monte Carlo \\
11 & 60366   & Monte Carlo \\
\end{tabular}
\caption{Durações das partidas} 
\label{montecarloduracoes}
\end{table}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.