Eu tenho a seguinte tabela:
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:
Responder1
\multicolumn
só 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 booktabs
recursos, 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}