업데이트

업데이트

다음 테이블이 있습니다.

여기에 이미지 설명을 입력하세요

코드에서:

\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}

하지만 오류가 발생합니다.

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

|테이블은 이전 에 이동된 것을 제외하고 거의 내가 원하는 대로 렌더링됩니다 165,00.

나타나는 오류를 제거하고 이동된 |파이프를 올바르게 정렬하는 방법은 무엇입니까?


업데이트

참고할 수 있는 좋은 목록:

  1. LaTeX 테이블의 다중 열 및 다중 행 셀
  2. https://en.wikibooks.org/wiki/LaTeX/Tables
  3. 테이블 형식, 테이블 형식* 및 테이블 형식x 환경의 차이점은 무엇입니까?
  4. 라텍스에서 다중 열 사용
  5. 라텍스 테이블 다중 행 및 다중 열

답변1

\multicolumn하나만 가질 수 있다하나열 지정자. 당신은 두 가지가 있습니다! 그런데 왜 그렇게 복잡한 머리 정의를 가지고 있습니까? 이는 동일하게 수행됩니다.

\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}

답변2

오류는 에 대한 인수에 있지만 \multicolumn테이블에 대한 잘못된 접근 방식을 취하고 있다고 생각합니다. TeX가 자체적으로 너비를 계산하므로 너비를 지정할 필요가 없습니다.

첫 번째 예와 두 번째 예는 본질적으로 동일하다는 것을 알 수 있습니다.

또한 siunitx. 이를 위해서는 테이블 헤더 입력에 약간의 주의가 필요하지만 보상은 큽니다.

마지막 예에서는 booktabs기능을 사용했지만 필수는 아닙니다.

\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}

여기에 이미지 설명을 입력하세요

관련 정보