Atualizar

Atualizar

Eu tenho a seguinte tabela:

insira a descrição da imagem aqui

Do código:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage[a4paper, margin=2cm]{geometry}

\usepackage{newtxtext,newtxmath}
\usepackage{array,ragged2e,tabularx,multirow}

\begin{document}
\section{Custos}

    \begin{tabular}
    {|
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{3.9cm}|} % Item
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{1.9cm}|} % Quantidade
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{3.0cm}|} % Valor, Valor
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{2.6cm}|} % Valor, Valor
    }
        \hline Item             &   Quantidade  &   Valor Unitário (R\$)    &   Valor Total (R\$) \\ \hline
        CD                      &   1           &   5,00                    &   5,00,00           \\ \hline
        Impressão               &   800         &   0,15                    &   120,00            \\ \hline
        Reserva Gerencial       &   1           &   20,00                   &   20,00             \\ \hline
        Reserva de Contingência &   1           &   20,00                   &   20,00             \\ \hline
        Total                   & \multicolumn{2}{c c|}{}                   &   165,00            \\ \hline

    \end{tabular}

\end{document}

Mas está lançando o erro:

 test.tex:29: Package array Error: Only one column-spec. allowed.. [...                  & \multicolumn{2}{c c}{}]

A tabela está sendo renderizada quase como eu gostaria, exceto pelo shifted |before 165,00.

Como evitar que o erro apareça e alinhar corretamente o |tubo deslocado?


Atualizar

Boa lista de referências:

  1. Células com múltiplas colunas e múltiplas linhas em tabelas LaTeX
  2. https://en.wikibooks.org/wiki/LaTeX/Tables
  3. Qual é a diferença entre ambientes tabular, tabular* e tabularx?
  4. Usando multicolunas em látex
  5. Tabela de látex com múltiplas linhas e múltiplas colunas

Responder1

\multicolumnsó pode terumespecificador de coluna. Você tem dois! No entanto, por que você tem uma definição de cabeça tão complicada? Isso faz o mesmo:

\begin{tabular}
    {|
        >{\RaggedRight}p{3.9cm}| 
        % Item
        >{\RaggedRight}p{1.9cm}|
        % Quantidade
        >{\RaggedRight}p{3.0cm}| 
        % Valor, Valor
        >{\RaggedRight}p{2.6cm}| }\hline 
    Item             &   Quantidade  &   Valor Unitário (R\$)    &   Valor 
    Total (R\$) \\ \hline
    CD                      &   1           &   5,00                    &   
    5,00,00           \\ \hline
    Impressão               &   800         &   0,15                    &   
    120,00            \\ \hline
    Reserva Gerencial       &   1           &   20,00                   &   
    20,00             \\ \hline
    Reserva de Contingência &   1           &   20,00                   &   
    20,00             \\ \hline
    Total                   & \multicolumn{2}{c|}{}                   &   
    165,00            \\ \hline 
\end{tabular}

Responder2

O erro está no argumento to \multicolumn, mas acho que você está adotando a abordagem errada para tabelas: não há necessidade de especificar a largura, pois o TeX irá calculá-la sozinho.

Você pode ver que o primeiro e o segundo exemplo são essencialmente os mesmos.

Também adicionei um terceiro exemplo para mostrar como é fácil obter alinhamento na vírgula decimal com siunitx. Isso requer alguma atenção na entrada dos cabeçalhos das tabelas, mas a recompensa é grande.

No exemplo final usei booktabsrecursos, mas eles não são obrigatórios.

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage[a4paper, margin=2cm]{geometry}

\usepackage{newtxtext,newtxmath}
\usepackage{array,ragged2e,tabularx,multirow}

\usepackage{booktabs,siunitx} % for the last example

\sisetup{output-decimal-marker={,}} % for siunitx

\begin{document}

\begin{table}[htp]
\centering
\caption{Original, with the fix}

    \begin{tabular}
    {|
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{3.9cm}|} % Item
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{1.9cm}|} % Quantidade
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{3.0cm}|} % Valor, Valor
        *1{@{\hspace{3.0pt}}>{ \RaggedRight\arraybackslash\hsize=1.1\hsize }p{2.6cm}|} % Valor, Valor
    }
        \hline Item             &   Quantidade  &   Valor Unitário (R\$)    &   Valor Total (R\$) \\ \hline
        CD                      &   1           &   5,00                    &   5,00              \\ \hline
        Impressão               &   800         &   0,15                    &   120,00            \\ \hline
        Reserva Gerencial       &   1           &   20,00                   &   20,00             \\ \hline
        Reserva de Contingência &   1           &   20,00                   &   20,00             \\ \hline
        Total                   & \multicolumn{2}{c|}{}                   &   165,00            \\ \hline

    \end{tabular}

\end{table}

\begin{table}[htp]
\centering
\caption{Simpler}

    \begin{tabular}{|l|l|l|l|}
        \hline Item             &   Quantidade  &   Valor Unitário (R\$)    &   Valor Total (R\$) \\ \hline
        CD                      &   1           &   5,00                    &   5,00              \\ \hline
        Impressão               &   800         &   0,15                    &   120,00            \\ \hline
        Reserva Gerencial       &   1           &   20,00                   &   20,00             \\ \hline
        Reserva de Contingência &   1           &   20,00                   &   20,00             \\ \hline
        Total                   & \multicolumn{2}{c|}{}                   &   165,00            \\ \hline

    \end{tabular}

\end{table}


\begin{table}[htp]
\centering

\caption{Better?}

\begin{tabular}{ l S[table-format=3.0] S[table-format=2.2] S[table-format=3.2] }
\toprule
{Item}                  & {Quantidade} & {Valor Unitário (R\$)} & {Valor Total (R\$)} \\
\midrule
CD                      &   1          &    5,00                &     5,00            \\
Impressão               &   800        &    0,15                &   120,00            \\
Reserva Gerencial       &   1          &   20,00                &    20,00            \\
Reserva de Contingência &   1          &   20,00                &    20,00            \\
\midrule
Total                   & \multicolumn{2}{c}{}                  &   165,00            \\
\bottomrule
\end{tabular}

\end{table}


\end{document}

insira a descrição da imagem aqui

informação relacionada