但我得到的却是
如果我输入一个较长的句子,它就会超出单元格,表格就会超出页面,而我需要它尊重边距
以下是该表的代码:
\begin{table}[H]
\centering
\setlength{\extrarowheight}{2pt}
\caption{Comparaison des méthodologies : convivialité}
\label{tab:conv_osstmm}
\begin{tabular}{|l|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|}
\hhline{~|--|}
\multicolumn{1}{c|}{\cellcolor[HTML]{FFFFFF}{}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{OSSTMM}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{ISSAF}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{PTES}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{NIST S 800-115}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{OWASP}}}\\\hline
\multirow{1}{*}{\textbf{Structure ordonnée bla bla}} & - & + & + & + & +\\ \hline
\multirow{1}{*}{\textbf{Connaissances de base}} & - & + & + & - & + \\
\hline
\end{tabular}
\end{table}
答案1
使用该tabularx
包:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{hhline, makecell,tabularx}
\renewcommand{\theadfont}{\small\bfseries}
\renewcommand{\theadgape}{} % <-------------------
\newcommand\mcw[1]{\multicolumn{1}{c}{\textcolor{white}{\thead{#1}}}}
\begin{document}
\begin{table}[ht]
\centering
\setlength{\extrarowheight}{2pt}
\caption{Comparaison des méthodologies : convivialité}
\label{tab:conv_osstmm}
\begin{tabularx}{\linewidth}{|X |*{5}{c|} }
\hhline{~|-----|}
\rowcolor{blue!45!black}
\multicolumn{1}{X}{\cellcolor{white}}
&\mcw{OSSTMM} &\mcw{ISSAF} & \mcw{PTES} & \mcw{NIST S\\ 800-115} & \mcw{OWASP} \\
\hhline{|------|}
\thead[l]{Structure\\ ordonnée bla bla} & -- & + & + & + & + \\
\hhline{|------|}
\thead[l]{Connaissances\\ de base} & -- & + & + & -- & + \\
\hhline{|------|}
\end{tabularx}
\end{table}
\end{document}
答案2
\documentclass{article}
\usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{aligned-overset}
\usepackage{cancel}
\usepackage{hhline}
\usepackage{multirow, makecell}
\begin{document}
\begin{table}
\centering
\setlength{\extrarowheight}{2pt}
\caption{Comparaison des méthodologies : convivialité}
\label{tab:conv_osstmm}
\begin{tabular}{|l|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|}
\hhline{~|--|}
\multicolumn{1}{c|}{\cellcolor[HTML]{FFFFFF}{}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{OSSTMM}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{ISSAF}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{PTES}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{NIST S 800-115}}}
&\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{OWASP}}}\\\hline
\textbf{\makecell[l]{here is \\ my text \\ in the cell}}& - & + & + & + & +\\ \hline
\multirow{1}{*}{\textbf{Connaissances de base}} & - & + & + & - & + \\
\hline
\end{tabular}
\end{table}
\end{document}
答案3
使用。您将不会在彩色面板中看到细白线(无论您使用哪种 PDF 查看器){NiceTabular}
。nicematrix
\documentclass{article}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{nicematrix}
\begin{document}
\begin{table}[ht]
\centering
\caption{Comparaison des méthodologies : convivialité}
\label{tab:conv_osstmm}
\begin{NiceTabular}{X[m,l]ccccc}[cell-space-limits=2pt]
& \RowStyle[color=white]{\sffamily} \Block[draw,fill=blue!45!black]{1-*}{}
OSSTMM & ISSAF & PTES & \Block{}{NIST S\\ 800-115} & OWASP \\
\Block[hvlines]{*-*}{}
Structure ordonnée bla bla bla & -- & + & + & + & + \\
Connaissances de base & -- & + & + & -- & + \\
\end{NiceTabular}
\end{table}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。