0

I'am writing my thesis. I want to create a table.

I'm using the tabularx environment My code:

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabularx}{\textwidth}{*{3}{>{\centering\arraybackslash}X}}
    \toprule
    \textbf{Aditivo} & {\textbf{Quantidade (g)} \\
    \cmidrule{2-3}
     & Carga Mineral (\%) \\
     & 20    & 30 \\
     \midrule
    Fibra & 1,266 & 252 \\
    GCC & 0,316 & 52 \\
    Amido & 0,016 & 25 \\
    ASA & 0,002 & 252 \\
    Percol & 0,00032 & 25 \\
    \bottomrule
    \end{tabularx}
  \label{tab_formacao_folhas}%
\end{table}%ckquote

enter image description here

But I want merging the text "Quantidade (g)" and "Carga Mineral" in second and third column. With tabularx , I can't use multicolumn.

  • just use \multicolumn{2}{c}{Quantidade (g} – David Carlisle May 31 '14 at 23:20
  • 3
    I wouldn't use tabularx for this in an any case, numeric columns would look better using dcolumn or siunitx so that the digits were aligned – David Carlisle May 31 '14 at 23:22
  • Can you give me a exemple of dcolumn or siunitx ? – user46548 May 31 '14 at 23:33
  • @user46548 Please see mirrors.ctan.org/macros/latex/required/tools/dcolumn.pdf pp 1-2, and mirrors.ctan.org/macros/latex/contrib/siunitx/siunitx.pdf. There should be plenty more examples over the Internet. – Masroor May 31 '14 at 23:38
  • 1
    You can use tabularx if you want but your comment that that means that you can not use \multicolumn is wrong. But please always post a complete document not just a fragment. (I would not use tabularx for this (even though I wrote that package) it is just three numeric columns so forcing the table to page width just makes it harder to read – David Carlisle Jun 1 '14 at 0:42
3

Please always post complete documents.

The comment about not being able to use \multicolumn with tabularx is wrong as shown in the first table below, but tabularx is really for adjusting the widths of paragraphs in p columns. Using it for numeric columns doesn't really produce a good result, it just spaces the table out, making it harder to read, and if you use \centering the numeric data isn't aligned. I'd use a setting more like the second table where the data aligns on the ,

enter image description here

\documentclass{article}

\usepackage{dcolumn,tabularx,booktabs}

\begin{document}

\begin{table}[htbp]
%  \centering does nothing if table is full width
  \caption{Add caption}
    \begin{tabularx}{\textwidth}{*{3}{>{\centering\arraybackslash}X}}
    \toprule
    \textbf{Aditivo} & \multicolumn{2}{c}{\textbf{Quantidade (g)}}\\
    \cmidrule{2-3}
     & \multicolumn{2}{c}{Carga Mineral (\%)} \\
     & 20    & 30 \\
     \midrule
    Fibra & 1,266 & 252 \\
    GCC & 0,316 & 52 \\
    Amido & 0,016 & 25 \\
    ASA & 0,002 & 252 \\
    Percol & 0,00032 & 25 \\
    \bottomrule
    \end{tabularx}
  \label{tab_formacao_folhas}%
\end{table}
\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cD{,}{,}{3.7}D{,}{,}{5.1}}
    \toprule
    \textbf{Aditivo} & \multicolumn{2}{c}{\textbf{Quantidade (g)}}\\
    \cmidrule{2-3}
     & \multicolumn{2}{c}{Carga Mineral (\%)} \\
     & \multicolumn{1}{c}{20}    &  \multicolumn{1}{c}{30} \\
     \midrule
    Fibra & 1,266 & 252 \\
    GCC & 0,316 & 52 \\
    Amido & 0,016 & 25 \\
    ASA & 0,002 & 252 \\
    Percol & 0,00032 & 25 \\
    \bottomrule
    \end{tabular}
  \label{tab_formacao_folhas2}%
\end{table}

\end{document}

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.