\newcolumntype{Y}{>{\raggedleft\arraybackslash}X} sequência de controle indefinida

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X} sequência de controle indefinida

Sou novo em LaTex e preciso de ajuda. Usei tabout no Stata para gerar uma tabela de resumo. Usando o código aqui recebo a seguinte mensagem de erro:

sequência de controle indefinida
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}

Aqui o código que usei:

\documentclass[11pt]{article}

\begin{document}

\begin{center}
\textbf{Table 9: A oneway table} \par \vspace{2ex}
\footnotesize
 \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {11cm} {@{} l Y Y Y Y @{}}
\toprule
 & Count & Col \% & Cum \% & Sample \\
\midrule 

\textbf{Industry} \\
Ag/Forestry/Fisheries & 84 & 0.8 & 0.8 & 17 \\
Mining & 14 & 0.1 & 0.9 & 4 \\
Construction & 160 & 1.4 & 2.3 & 29 \\
Manufacturing & 1,848 & 16.6 & 18.9 & 367 \\
Transport/Comm/Utility & 433 & 3.9 & 22.8 & 90 \\
Wholesale/Retail Trade & 1,685 & 15.1 & 37.9 & 333 \\
Finance/Ins/Real Estate & 970 & 8.7 & 46.7 & 192 \\
Business/Repair Svc & 429 & 3.9 & 50.5 & 86 \\
Personal Services & 472 & 4.2 & 54.8 & 97 \\
Entertainment/Rec Svc & 99 & 0.9 & 55.6 & 17 \\
Professional Services & 4,151 & 37.3 & 92.9 & 824 \\
Public Administration & 786 & 7.1 & 100.0 & 176 \\
Total & 11,129 & 100.0 &  & 2,232 \\
\midrule 

\textbf{Occupation} \\
Professional/technical & 1,477 & 13.2 & 13.2 & 317 \\
Managers/admin & 1,322 & 11.8 & 25.1 & 264 \\
Sales & 3,626 & 32.5 & 57.5 & 726 \\
Clerical/unskilled & 511 & 4.6 & 62.1 & 102 \\
Craftsmen & 239 & 2.1 & 64.2 & 53 \\
Operatives & 1,305 & 11.7 & 75.9 & 246 \\
Transport & 136 & 1.2 & 77.1 & 28 \\
Laborers & 1,491 & 13.4 & 90.5 & 286 \\
Farmers & 8 & 0.1 & 90.5 & 1 \\
Farm laborers & 40 & 0.4 & 90.9 & 9 \\
Service & 75 & 0.7 & 91.6 & 16 \\
Household workers & 3 & 0.0 & 91.6 & 2 \\
Other & 938 & 8.4 & 100.0 & 187 \\
Total & 11,171 & 100.0 &  & 2,237 \\
\bottomrule
\end{tabularx}
\par\smallskip\noindent\parbox{11cm}{\raggedright \scriptsize Source: nlsw88.dta}
\normalsize
\end{center}

\end{document}

Responder1

Modificando seu código

Se você alterar sua definição de tipo de coluna R para Y e adicionartabularxeguias de livros, seu exemplo compila sem erros:

\documentclass[11pt]{article}
\usepackage{tabularx, booktabs} %% Load packages that you use

\begin{document}

\begin{center}
%%\textbf{Table 9: A oneway table} \par \vspace{2ex} %% To avoid label on separate page
\footnotesize
 \newcolumntype{Y}{>{\raggedleft\arraybackslash}X} %% You defined R, but used Y
\begin{tabularx} {11cm} {@{} l Y Y Y Y @{}}
\multicolumn{5}{@{}c}{\normalsize\bfseries Table 9: A oneway table}\\\addlinespace[2ex]  %% Label as part of the table
\toprule
 & Count & Col \% & Cum \% & Sample \\
\midrule 

\textbf{Industry} \\
Ag/Forestry/Fisheries & 84 & 0.8 & 0.8 & 17 \\
Mining & 14 & 0.1 & 0.9 & 4 \\
Construction & 160 & 1.4 & 2.3 & 29 \\
Manufacturing & 1,848 & 16.6 & 18.9 & 367 \\
Transport/Comm/Utility & 433 & 3.9 & 22.8 & 90 \\
Wholesale/Retail Trade & 1,685 & 15.1 & 37.9 & 333 \\
Finance/Ins/Real Estate & 970 & 8.7 & 46.7 & 192 \\
Business/Repair Svc & 429 & 3.9 & 50.5 & 86 \\
Personal Services & 472 & 4.2 & 54.8 & 97 \\
Entertainment/Rec Svc & 99 & 0.9 & 55.6 & 17 \\
Professional Services & 4,151 & 37.3 & 92.9 & 824 \\
Public Administration & 786 & 7.1 & 100.0 & 176 \\
Total & 11,129 & 100.0 &  & 2,232 \\
\midrule 

\textbf{Occupation} \\
Professional/technical & 1,477 & 13.2 & 13.2 & 317 \\
Managers/admin & 1,322 & 11.8 & 25.1 & 264 \\
Sales & 3,626 & 32.5 & 57.5 & 726 \\
Clerical/unskilled & 511 & 4.6 & 62.1 & 102 \\
Craftsmen & 239 & 2.1 & 64.2 & 53 \\
Operatives & 1,305 & 11.7 & 75.9 & 246 \\
Transport & 136 & 1.2 & 77.1 & 28 \\
Laborers & 1,491 & 13.4 & 90.5 & 286 \\
Farmers & 8 & 0.1 & 90.5 & 1 \\
Farm laborers & 40 & 0.4 & 90.9 & 9 \\
Service & 75 & 0.7 & 91.6 & 16 \\
Household workers & 3 & 0.0 & 91.6 & 2 \\
Other & 938 & 8.4 & 100.0 & 187 \\
Total & 11,171 & 100.0 &  & 2,237 \\
\bottomrule
\multicolumn{5}{@{}l}{\scriptsize{Source: nlsw88.dta}}\\
\end{tabularx}
%% \par\smallskip\noindent\parbox{11cm}{\raggedright \scriptsize Source: nlsw88.dta} %% to avoid source reference on a separate page
\normalsize
\end{center}

\end{document}

Saiba também que o ambiente centro acrescenta espaço antes e depois da mesa. Além disso, como o rótulo e a referência da fonte são linhas de texto separadas, você pode acabar com um desses itens sendo composto em uma página separada. Adicione algumas linhas de texto antes da tabela para ver o efeito.

Você pode evitar esse efeito de várias maneiras. Uma solução rápida e suja é colocar o rótulo e a referência da fonte dentro da tabela, adicionando novas primeiras e últimas linhas. Use \multicolumnpara abranger todas as células em uma linha da tabela:

Rótulo:

\multicolumn{5}{@{}c}{\normalsize\bfseries Table 9: A oneway table}\\\addlinespace[2ex]

Referência da fonte:

\bottomrule\addlinespace[0.5ex]
\multicolumn{5}{@{}l}{\scriptsize{Source: nlsw88.dta}}\\

Veja MWE atualizado.

Você também pode colocar todo o ambiente central, incluindo a mesa, em um minipageambiente ou em uma caixa.

Talvez uma solução mais elegante seja usar o pacotemesa de três partesou, se você aceitar a tabela como flutuante, coloque a tabela dentro de um ambiente de tabela.

Usando três partes

Aqui está um MWE usando threeparttable. Eu adicionei algum texto acima e abaixo para demonstrar a configuração. Se você incluir toda a sua tabela com threeparttablelegenda, terá numeração automática e mesma formatação para todas. Adicionar rótulosdepoisas legendas, e você pode consultar automaticamente as tabelas por número em seu texto:

\documentclass[11pt]{article}
\usepackage{tabularx, booktabs, threeparttable, caption}

\captionsetup{font=bf, aboveskip=1ex, belowskip=2ex}

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}

\begin{document}


Text before \emph{threeparttable}. Even more text. Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text. Even more text. See table~\ref{table:onewaytable}:

\begingroup
\centering
\begin{threeparttable}[b]
\caption{A oneway table}
\label{table:onewaytable} %% Add a label after the caption
\footnotesize
\begin{tabularx} {11cm} {@{} l Y Y Y Y @{}}
\toprule
 & Count & Col \% & Cum \% & Sample \\
\midrule 

\textbf{Industry} \\
Ag/Forestry/Fisheries & 84 & 0.8 & 0.8 & 17 \\
Mining & 14 & 0.1 & 0.9 & 4 \\
Construction & 160 & 1.4 & 2.3 & 29 \\
Manufacturing & 1,848 & 16.6 & 18.9 & 367 \\
Transport/Comm/Utility & 433 & 3.9 & 22.8 & 90 \\
Wholesale/Retail Trade & 1,685 & 15.1 & 37.9 & 333 \\
Finance/Ins/Real Estate & 970 & 8.7 & 46.7 & 192 \\
Business/Repair Svc & 429 & 3.9 & 50.5 & 86 \\
Personal Services & 472 & 4.2 & 54.8 & 97 \\
Entertainment/Rec Svc & 99 & 0.9 & 55.6 & 17 \\
Professional Services & 4,151 & 37.3 & 92.9 & 824 \\
Public Administration & 786 & 7.1 & 100.0 & 176 \\
Total & 11,129 & 100.0 &  & 2,232 \\
\midrule 

\textbf{Occupation} \\
Professional/technical & 1,477 & 13.2 & 13.2 & 317 \\
Managers/admin & 1,322 & 11.8 & 25.1 & 264 \\
Sales & 3,626 & 32.5 & 57.5 & 726 \\
Clerical/unskilled & 511 & 4.6 & 62.1 & 102 \\
Craftsmen & 239 & 2.1 & 64.2 & 53 \\
Operatives & 1,305 & 11.7 & 75.9 & 246 \\
Transport & 136 & 1.2 & 77.1 & 28 \\
Laborers & 1,491 & 13.4 & 90.5 & 286 \\
Farmers & 8 & 0.1 & 90.5 & 1 \\
Farm laborers & 40 & 0.4 & 90.9 & 9 \\
Service & 75 & 0.7 & 91.6 & 16 \\
Household workers & 3 & 0.0 & 91.6 & 2 \\
Other & 938 & 8.4 & 100.0 & 187 \\
Total & 11,171 & 100.0 &  & 2,237 \\
\bottomrule
\end{tabularx}
\scriptsize
\begin{tablenotes}[flushleft]
\item Source: nlsw88.dta
\end{tablenotes}\smallskip
\end{threeparttable}%

\endgroup


More text. Even more text. Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.Even more text.

\end{document}

insira a descrição da imagem aqui

informação relacionada