警告:LaTeX
我对标记和这整个事情还很陌生。
\documentclass[a4paper,svgnames,11pt]{article}
\textheight = 220mm
\textwidth = 150mm
\topmargin = 10mm
\oddsidemargin = 5.0mm
\evensidemargin = 5.0mm
\unitlength = 1mm
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\pagenumbering{Roman}
\usepackage[margin=2cm]{geometry}
\usepackage[final]{pdfpages}
\usepackage{longtable}
\usepackage{color}
\usepackage{xcolor,colortbl}
\begin{document}
\begin{longtable}{|p{3cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\caption{Comparisons}\label{tab1}\small\\
\hline\rowcolor{Black}
Column & Column & Column & Column &
Column & Column & Column \\ \hline
\raggedright Hello & Hello & Hello & Hello & Hello & Hello & \\ \hline
\raggedright Hello & Hello & Hello & Hello & Hello & Hello & \\ \hline
\raggedright Hello & Hello & Hello & Hello & Hello & Hello & \\ \hline
\end{longtable}
\end{document}
如何才能使其变得更紧凑、更容易修改、重复大小、列文本为白色、单元格内稍微居中。
\newcolumntype{F}[1]{%
>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%
\newcolumntype{T}[1]{%
>{\centering\arraybackslash\hspace{0pt}}p{#1}}%
或者,
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
答案1
(对我而言)您不太清楚自己想要什么,所以我想您可能会对以下解决方案感兴趣:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\NewTblrTheme{fancy caption}%
{
\SetTblrStyle{caption-text}{\small\itshape}
\SetTblrStyle{caption-tag}{font=\small\bfseries}
}
\ExplSyntaxOn
\NewChildSelector{eachtwohline}
{
\int_step_inline:nnnn {4} {2} { \l_tblr_childs_total_tl }
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
\usepackage{dingbat}
\newcommand\gcm{\textcolor{teal}{\checkmark}}% GreenCheckMark
\begin{document}
\begin{talltblr}[
theme = fancy caption,
caption = {Table caption},
label = {tab:talltblr}
]{hline{eachtwohline} = {dashed, 0.1pt},
colspec = {Q[l,m, wd=33mm]
*{6}{Q[c,m]}},
colsep = 4pt,
rowsep = 1pt,
hline{Z} = 1pt,
rows = {font=\linespread{0.84}\selectfont},
row{1} = {fg=white, bg=black!80},
}
Head & {first\\second}
& {first\\second}
& {first\\second}
& {first\\second}
& {first\\second}
& {first\\second}
\\
DAO attack
& & \gcm & & & & \\
Attack on wallet software
& & \gcm & \gcm & & \gcm & \\
Criminal Activity
& & & \gcm & & & \\
\qty{51}{\%} attack
& & \gcm & & \gcm & & \\
Pool hopping attack
& & & & & & \gcm \\
% etc
Distributed Denial of Service (DDoS)
& & & \gcm & & & \\
\end{talltblr}
\end{document}
答案2
您可以使用tabularray
包。它使处理表格样式更加容易。这是一个例子。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularray}
\usepackage{ninecolors}
\begin{document}
\begin{longtblr}[
caption = {Table cpation},
label = {tab:long1}
]{
hlines, vlines,
colspec = {Q[3cm, l, m] *{6}{Q[2cm, c, m]}}, %1st column is 3cm and left aligned, all other 6 columns are centered
rows = {bg=black, fg=white, font=\small}, %black background, white text with small font size
rowhead = 1, %1st row will appear in every page
}
Head & Relatively long Head & Head & Head & Head & Head & Head\\ %This row will appear in every page
Hello & \SetCell[r=2]{c} Hello & Long Hello & More long Hello & Hello & Hello &\\
Hello & & Hello & Hello & Hello & Hello &\\
Hello & Hello & Hello & Hello & Hello & Hello &\\
\end{longtblr}
\end{document}
笔记:
- 您可以考虑避免使用所有垂直线和大部分水平线。这样可以使表格更专业。
- 此表格比文本宽度更宽。您可以考虑减小列宽。
编辑(根据 OP 的评论):如果您所说的紧凑是指减少行之间的空间,那么您可以使用选项来更改它rowsep
。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularray}
\usepackage{ninecolors}
\begin{document}
\begin{longtblr}[
caption = {Table cpation},
label = {tab:long1}
]{
% abovesep=0pt,%removes any vertical space above
% belowsep=0pt,%removes any vertical space below
rowsep = 0pt, %removes any vertical space above and below.
hlines, vlines,
colspec = {Q[3cm, l, m] *{6}{Q[2cm, c, m]}}, %1st column is 3cm and left aligned, all other 6 columns are centered
rows = {font=\small}, %black background, white text with small font size
row{1} = {bg=black, fg=white},
rowhead = 1, %1st row will appear in every page
}
Head & Head & Head & Head & Head & Head & Head\\ %This row will appear in every page
Hello & Hello & Hello & Hello & Hello & Hello &\\
Hello & & Hello & Hello & Hello & Hello &\\
Hello & Hello & Hello & Hello & Hello & Hello &\\
\end{longtblr}
\end{document}