4

I need to create a table with a specific aspect. How did I create the table that I annexed to this message?

\documentclass[11pt]{article}
\usepackage{mathtools,float}
\usepackage{amstext}
\usepackage{booktabs,tabularx}
\usepackage{ragged2e}

\begin{document}

\begin{table}[H]    
\centering    
\begin{tabular}{c|c|c|c|c}    
\toprule    
 & Para os 10 per\'{i}odos & Medida (valor final)/ 10 per\'{i}odos &
 Para um per\'{i}odo & Medida (valor final)\\    
\midrule    
\hline M\'{e}dia & 14,04 & 14,04 & 1,404 & 1,40\\    
\hline Desvio Padr\~{a}o & 0,095770401 & 0,10 & 0,0095770401 & 0,01\\
\hline N contagens & 12 & 12 & 12 & 12\\    
\bottomrule    
\end{tabular}    
\end{table}

\end{document}
10
  • 1
    Hey there :) I don't think you've successfully attached your desired table to this post, but in any case, you should quote the full error message you received and also show us what you've done so far. This last bit is really important, not just because it shows us that you've actually tried and makes us feel less like an unpaid typesetting service, but because it may also give us a starting point and, if you include a full MWE, shows us what packages you're using and your setup, which could drastically alter how we approach the question and what works and what doesn't!
    – Au101
    Commented Apr 10, 2016 at 2:06
  • 1
    Good, that's better, and you were right to edit it into the original question, I was just about to ask you to do that, but you should really make it into a full MWE, with your preamble and a \begin{document} and an \end{document}
    – Au101
    Commented Apr 10, 2016 at 2:19
  • 1
    You are using rules from booktabs with both \hlines and vertical lines - I'm not surprised the result doesn't look very good! Did you look at booktabs's documentation?
    – cfr
    Commented Apr 10, 2016 at 2:30
  • 1
    And do please consider accepting answers for some of your existing questions.
    – cfr
    Commented Apr 10, 2016 at 2:33
  • 1
    @Au101 -- Ah, I see. Will delete comments ... because, as I now think, there's actually no error, just a desire for a nicer table.
    – jon
    Commented Apr 10, 2016 at 2:37

3 Answers 3

5

The first thing I would do is load geometry which will use slightly more sensible margins than LaTeX does by default. Since the table is too wide, you have a few options:

  1. make the text of the table smaller e.g. with \small or \footnotesize;
  2. rotate the table using options from, of example, the rotating package;
  3. allow cells to break within columns;
  4. add notes to the table for supplemental information;
  5. reduce the spacing;
  6. some combination of two or more of the above.

(1) and (5) will make the table harder for readers. Especially, I would recommend not doing (5) and, if you do use (1), don't do it to excess. \small may be acceptable if you are using a reasonably sized font. \tiny probably won't be.

In the table below, I use (3) and (4). For (3), I use a tabularx environment consisting of one l column and four X columns. I then use (4) to move some information into a table note using threeparttable. Note that I don't have much idea of the meaning as I don't speak the language. So my selection is based purely on the punctuation and you may well wish to move something different into the notes. But this should at least demonstrate how to do that.

Follow the booktabs guidelines as these are good for at least 98% of cases, probably more:

  • \toprule, \midrule and \bottomrule (+ \cmidrule{} if required in more complex tables);
  • no vertical rules;
  • no double horizontal rules and, certainly, no \hlines.

\toprule and friends are designed to replace \hline etc. - they should not be used as well.

So these changes produce something like the following result:

modified table

It would be better, really, if the numbers were aligned on the decimal point. However, I had better leave that to the siunitx experts as I can only manage it for very simple cases.

\documentclass[11pt]{article}
\usepackage{mathtools,float,geometry}
\usepackage{booktabs,array,tabularx,threeparttablex}
\begin{document}
\begin{table}[H]
  \begin{threeparttable}
    \begin{tabularx}{\linewidth}{l*{4}{>{\centering\arraybackslash}X}}
      \toprule
      & Para os 10 per\'{i}odos & Medida\tnote{\textasteriskcentered} / 10 per\'{i}odos & Para um per\'{i}odo & Medida\tnote{\textasteriskcentered}\\
      \midrule
      M\'{e}dia & 14,04 & 14,04 & 1,404 & 1,40\\
      Desvio Padr\~{a}o & 0,095770401 & 0,10 & 0,0095770401 & 0,01\\
      N contagens & 12 & 12 & 12 & 12\\
      \bottomrule
    \end{tabularx}
    \begin{tablenotes}
      \item[\textasteriskcentered]valor final
    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}
4

Some suggestions:

  • Use fewer significant digits - What information is conveyed by 0,0095770401 which isn't also conveyed by, say, 0,009577?

  • Keep using c as the column type for the numbers in columns 2 to 5, but use a column type that allows automatic line wrapping for the text in the header cells. I suggest you employ a tabularx environment, set its overall width to \textwidth, and use a centered version of the X column type for the 4 header cells.

  • I see no need for the interior \hline directives.

enter image description here

\documentclass[11pt]{article}
\usepackage[portuguese]{babel}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{@{}C@{}}{#1}} % handy shortcut macro

\begin{document}

\begin{table}
\begin{tabularx}{\textwidth}{@{} l cccc @{}}
\toprule
& \mC{Para os 10~per\'{i}odos} 
& \mC{Medida (valor~final)/ 10~per\'{i}odos} 
& \mC{Para um~per\'{i}odo} 
& \mC{Medida (valor~final)} \\
\midrule
M\'{e}dia         & 14,04   & 14,04 & 1,404    & 1,40\\
Desvio Padr\~{a}o & 0,09577 & 0,10  & 0,009577 & 0,01\\
N contagens       & 12      & 12    & 12       & 12\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}
4

As supplement to @cfr answer:

  • for column heads are used macro thead from package makecell
  • for aligning of numbers at decimal point is used S column type from package siunitx
  • instead of tabularx is used ordinary tabular environment

With this changes you can obtain:

enter image description here

The code:

\documentclass[11pt]{article}
    \usepackage{mathtools,float,geometry}
    \usepackage{array,booktabs,makecell,tabularx,threeparttable}
\renewcommand\theadfont{\normalfont}
    \usepackage{siunitx}

\begin{document}
\begin{table}
  \begin{threeparttable}
    \begin{tabular}{l*{2}{S[table-format=3.11]S[table-format=4.3]}}
      \toprule
    &   {\thead{Para os 10\\ per\'{i}odos}} 
        &   {\thead{Medida\tnote{\textasteriskcentered} / 10\\ per\'{i}odos}}
            &   {\thead{Para um\\ per\'{i}odo}} 
                &   {\thead[b]{Medida\tnote{\textasteriskcentered}}}\\
      \midrule
M\'{e}dia           & 14,04         & 14,04 & 1,404         & 1,40  \\
Desvio Padr\~{a}o   & 0,095770401   & 0,10  & 0,0095770401  & 0,01  \\
      N contagens   & 12            & 12    & 12            & 12    \\
      \bottomrule
    \end{tabular}
  \begin{tablenotes}
      \item[\textasteriskcentered]valor final
    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

Caveat: I'm not a siunitx expert, I only use it frequently ...

Edit:

Considering Mico comment let be noted:

  • by loading of the geometry package the \textwidth is automatically increases from 360pt to 430pt. This means, that for table is with it more apace, i.e. the numbers with 11 decimal places can be set in full lenght. Otherwise, it had to be rounded on less decimal places, for examplt to five as manulay did Mico in his answer
  • with option table-auto-round in combination with for example table-format=3.5 the numbers in table is rounded to five decimal places and shorter numbers padded with zero to the given number of decimals
  • with siunitx option output-decimal-marker={,} the decimal marker is changed from dot to coma (as seems that the OP appears to wish to use commas.

To better see the influence of above consideration an table layout, I add showframe package and center table on text width. The complete renewed code is:

\documentclass[11pt]{article}
    \usepackage{booktabs,makecell,threeparttable}
\renewcommand\theadfont{\normalfont}
    \usepackage[output-decimal-marker={,}]{siunitx}

    \usepackage{showframe}

\begin{document}
\begin{table}
\centering
  \begin{threeparttable}
    \begin{tabular}{l*{2}{S[table-format=3.5,
                            table-auto-round]S[table-format=4.3]}}
      \toprule
    &   {\thead{Para os 10\\ per\'{i}odos}}
        &   {\thead{Medida\tnote{\textasteriskcentered} / 10\\ per\'{i}odos}}
            &   {\thead{Para um\\ per\'{i}odo}}
                &   {\thead[b]{Medida\tnote{\textasteriskcentered}}}\\
      \midrule
M\'{e}dia           & 14,04         & 14,04 & 1,404         & 1,40  \\
Desvio Padr\~{a}o   & 0,095770401   & 0,10  & 0,0095770401  & 0,01  \\
      N contagens   & 12            & 12    & 12            & 12    \\
      \bottomrule
    \end{tabular}
  \begin{tablenotes}
      \item[\textasteriskcentered]valor final
    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

Obtained result:

enter image description here

2
  • 3
    You may want to state somewhere that loading the geometry package automatically increases \textwidth, from 360pt to 430pt. If geometry weren't loaded, the table would be too wide for the text block. One way to fix this, i.e., to make the table fit in the text block even if geometry isn't loaded, would be to show fewer places after the decimal markers in columns 2 and 4. Incidentally, one should set the option output-decimal-marker={,}, as the OP appears to wish to use commas rather than dots to as the decimal markers.
    – Mico
    Commented Apr 10, 2016 at 13:05
  • 1
    @Mico, I consider your comment (+1 for it!) and edit my answer.
    – Zarko
    Commented Apr 10, 2016 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .