在寻求帮助之前,我在这里搜索过,但没有成功。
我有一个长表 latex(我使用的是 longtable 环境)。我想将某些特定行涂成灰色(行:2、4、5、6、11、12、13、15、17、21、29 和 32)。你们能帮我实现这个吗?提前谢谢大家。这是我的代码:
\documentclass{article}
\usepackage{longtable}
\usepackage{rotating,tabularx,booktabs,siunitx,caption}
\usepackage{colortbl, xcolor}
\usepackage{adjustbox}
\usepackage{makecell}
\title{A longtable example}
\begin{document}
\begin{center}
\small
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{1.5pt}
\begin{longtable}{ccccc}
\caption{Tabela Nome dos Candidatos. Elaborado por Autor. 2020.} \label{tab:tabelaNomeCandidatosColigacao} \\
\toprule
\multicolumn{1}{c}{\textbf{\makecell{Número \\ do Candidato}}} &
\multicolumn{1}{l}{\textbf{\makecell{Nome do Candidato \\ (urna)}}} &
\multicolumn{1}{c}{\textbf{Partido}} &
\multicolumn{1}{c}{\textbf{\makecell{Votos Nominais \\ do Candidato}}} &
\multicolumn{1}{c}{\textbf{\makecell{\% Votos \\ Válidos}}} \\
\midrule
\endfirsthead
\toprule
\multicolumn{1}{c}{\textbf{Número do Candidato}} &
\multicolumn{1}{l}{\textbf{\makecell{Nome do Candidato \\ (urna)}}} &
\multicolumn{1}{c}{\textbf{Partido}} &
\multicolumn{1}{c}{\textbf{\makecell{Votos Nominais \\ do Candidato}}} &
\multicolumn{1}{c}{\textbf{\makecell{\% Votos \\ Válidos}}} \\
\midrule
\endhead
\midrule
\endfoot
\bottomrule
\endlastfoot
44444 & JORGE KAJURU & PRP & 37.796 & 5,65 \\
\rowcolor{gray!40}
45233 & DRA. CRISTINA & PSDB & 9.114 & 1,36 \\
\makecell{90100} & \makecell{VINICIUS CIRQUEIRA} & \makecell{PROS} & 8.582 & 1,28 \\
\rowcolor{gray!40!}
10123 & ROGERIO CRUZ & PRB & 8.312 & 1,24 \\
\rowcolor{gray!40!}
45602 & ANSELMO PEREIRA & PSDB & 7.504 & 1,12 \\
\rowcolor{gray!40!}
40001 & ELIAS VAZ & PSB & 7.487 & 1,12 \\
23456 & CARLIN CAFÉ & PPS & 7.392 & 1,1 \\
\makecell{10010} & \makecell{ALYSSON LIMA} & \makecell{PRB} & 7.257 & 1,08 \\
\makecell{35789} & \makecell{SABRINA GARCEZ} & \makecell{PMB} & 7.233 & 1,08 \\
\makecell{22222} & \makecell{FELISBERTO TAVARES} & \makecell{PR} & 6.670 & 1 \\
\rowcolor{gray!40!}
15700 & WELINGTON PEIXOTO & PMDB & 6.513 & 0,97 \\
\rowcolor{gray!40!}
12345 & PAULINHO GRAUS & PDT & 6.452 & 0,96 \\
\rowcolor{gray!40!}
40321 & OSÉIAS VARÃO & PSB & 6.171 & 0,92 \\
\makecell{22123} & \makecell{IZIDIO ALVES} & \makecell{PR} & 5.889 & 0,88 \\
\rowcolor{gray!40!}
27500 & KLEYBE MORAIS & PSDC & 5.818 & 0,87 \\
\makecell{15015} & \makecell{CLECIO ALVES} & \makecell{PRP} & 5.415 & 5,65 \\
\rowcolor{gray!40!}
90900 & TIAOZINHO PORTO & PROS & 4.878 & 0,73 \\
\makecell{55555} & \makecell{PRISCILLA TEJOTA} & \makecell{PSD} & 4.807 & 0,72 \\
\makecell{17000} & \makecell{LUCAS KITÃO} & \makecell{PSL} & 4.499 & 0,67 \\
\makecell{55015} & \makecell{PAULO MAGALHÃES} & \makecell{PSD} & 4.482 & 0,67 \\
\rowcolor{gray!40!}
65123 & TATIANA LEMOS & PC do B & 4.418 & 0,66 \\
\makecell{43444} & \makecell{DELEGADO EDUARDO PRADO} & \makecell{PV} & 4.237 & 0,63 \\
\makecell{15678} & \makecell{ANDREY AZEREDO} & \makecell{PMDB} & 4.073 & 0,61 \\
\makecell{43400} & \makecell{GUSTAVO CRUVINEL} & \makecell{PV} & 4.066 & 0,61 \\
\makecell{27900} & \makecell{JAIR DIAMANTINO} & \makecell{PSDC} & 3.889 & 0,58 \\
\makecell{28123} & \makecell{JUAREZ LOPES} & \makecell{PRTB} & 3.753 & 0,56 \\
\makecell{27100} & \makecell{ANDERSON SALES BOKÃO} & \makecell{PSDC} & 3.479 & 0,52 \\
\rowcolor{gray!40!}
51800 & ZANDER & PEN & 3.501 & 0,52 \\
20500 & LEIA KLEBIA & PSC & 3.367 & 0,5 \\
\makecell{36153} & \makecell{GCM ROMÁRIO POLICARPO} & \makecell{PTC} & 3.185 & 0,48 \\
\makecell{44321} & \makecell{MILTON MERCEZ} & \makecell{PRP} & 2.886 & 0,43 \\
\makecell{44190} & \makecell{CABO SENNA} & \makecell{PRP} & 2.795 & 0,42 \\
19123 & SARGENTO NOVANDIR & PTN & 2.713 & 0,41 \\
\rowcolor{gray!40!}
25555 & DR. PAULO DAHER & DEM & 2.511 & 0,38 \\
\makecell{19123} & \makecell{EMILSON PEREIRA} & \makecell{PTN} & 2.429 & 0,36 \\
\end{longtable}
\end{center}
\end{document}
答案1
以下内容可以作为起点。由于原始代码中没有给出有关边距大小的其他信息的 documentclass,因此我猜测:
\documentclass{article}
\usepackage{longtable}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\begin{document}
{
\small
\setlength{\tabcolsep}{5pt}
\begin{longtable}{cllcc}
\caption{Tabela Nome dos Candidatos. Elaborado por Autor. 2020.}
\label{tab:tabelaNomeCandidatosColigacao} \\
\toprule
\thead{Número \\ do\\ Candidato} &
\thead{Nome do Candidato \\ (urna)} &
\thead{Partido} &
\thead{Votos\\ Nominais do\\ Candidato} &
\thead{\% Votos \\ Válidos} \\
\midrule
\endfirsthead
\toprule
\thead{Número \\ do\\ Candidato} &
\thead{Nome do Candidato \\ (urna)} &
\thead{Partido} &
\thead{Votos\\ Nominais do\\ Candidato} &
\thead{\% Votos \\ Válidos} \\
\midrule
\endhead
\midrule
\endfoot
\bottomrule
\endlastfoot
44444 & JORGE KAJURU & PRP & 37.796 & 5,65 \\
\rowcolor{lightgray} 45233 & DRA. CRISTINA & PSDB & 9.114 & 1,36 \\
90100 & VINICIUS CIRQUEIRA & PROS & 8.582 & 1,28 \\
\rowcolor{lightgray} 10123 & ROGERIO CRUZ & PRB & 8.312 & 1,24 \\
\rowcolor{lightgray} 45602 & ANSELMO PEREIRA & PSDB & 7.504 & 1,12 \\
\rowcolor{lightgray} 40001 & ELIAS VAZ & PSB & 7.487 & 1,12 \\
23456 & CARLIN CAFÉ & PPS & 7.392 & 1,1 \\
10010 & ALYSSON LIMA & PRB & 7.257 & 1,08 \\
35789 & SABRINA GARCEZ & PMB & 7.233 & 1,08 \\
22222 & FELISBERTO TAVARES & PR & 6.670 & 1 \\
15700 & WELINGTON PEIXOTO & PMDB & 6.513 & 0,97 \\
12345 & PAULINHO GRAUS & PDT & 6.452 & 0,96 \\
40321 & OSÉIAS VARÃO & PSB & 6.171 & 0,92 \\
22123 & IZIDIO ALVES & PR & 5.889 & 0,88 \\
27500 & KLEYBE MORAIS & PSDC & 5.818 & 0,87 \\
15015 & CLECIO ALVES & PRP & 5.415 & 5,65 \\
90900 & TIAOZINHO PORTO & PROS & 4.878 & 0,73 \\
55555 & PRISCILLA TEJOTA & PSD & 4.807 & 0,72 \\
17000 & LUCAS KITÃO & PSL & 4.499 & 0,67 \\
55015 & PAULO MAGALHÃES & PSD & 4.482 & 0,67 \\
65123 & TATIANA LEMOS & PC do B & 4.418 & 0,66 \\
43444 & DELEGADO EDUARDO PRADO & PV & 4.237 & 0,63 \\
15678 & ANDREY AZEREDO & PMDB & 4.073 & 0,61 \\
43400 & GUSTAVO CRUVINEL & PV & 4.066 & 0,61 \\
27900 & JAIR DIAMANTINO & PSDC & 3.889 & 0,58 \\
28123 & JUAREZ LOPES & PRTB & 3.753 & 0,56 \\
27100 & ANDERSON SALES BOKÃO & PSDC & 3.479 & 0,52 \\
51800 & ZANDER & PEN & 3.501 & 0,52 \\
20500 & LEIA KLEBIA & PSC & 3.367 & 0,5 \\
36153 & GCM ROMÁRIO POLICARPO & PTC & 3.185 & 0,48 \\
44321 & MILTON MERCEZ & PRP & 2.886 & 0,43 \\
44190 & CABO SENNA & PRP & 2.795 & 0,42 \\
19123 & SARGENTO NOVANDIR & PTN & 2.713 & 0,41 \\
25555 & DR. PAULO DAHER & DEM & 2.511 & 0,38 \\
19123 & EMILSON PEREIRA & PTN & 2.429 & 0,36 \\
\end{longtable}
}
\end{document}