更新
两个都大卫·卡莱尔'沙斯基尔蒙的答案很棒(并且发布时间相隔不到 10 秒),但 SO 只允许我将一个标记为正确,因此我鼓励遇到此问题的任何人像我一样尝试两个(因为这两个都是针对我的不同失误的解决方案,但结果相同)。
原始帖子:
如何修改以下嵌套的水平间距/填充tabulars
,以便两个相关单元格中的突出显示能够触及左右单元格边框?
我浏览过许多,许多 答案但找不到有效的解决方案。任何帮助都将不胜感激!
表格如下:
\begin{table}[ht]
\centering
\caption{Caption above table.}
\begin{tabular}{|c|c|l|p{5cm}|}
\hline
% column headers
Record & Prepend & \multicolumn{1}{c|}{Name} & \multicolumn{1}{c|}{Value} \\ \hline
% A (ipv4 records)
\texttt{A} & www &
\begin{tabular}{@{\hskip3pt}l}
\colorbox{white}{%
\begin{tabular}[c]{@{}l}
\texttt{mydomain.tld}
\end{tabular}
} \\
\colorbox{yellow}{%
\begin{tabular}[c]{@{}l}
\texttt{autoconfig.mydomain.tld}\\
\texttt{imap.mydomain.tld}\\
\texttt{mail.mydomain.tld}\\
\texttt{pop.mydomain.tld}\\
\texttt{smtp.mydomain.tld}
\end{tabular}
}
\end{tabular} & \texttt{111.222.111.222} \\ \hline
% AAAA (ipv6) records
\texttt{AAAA} & www &
\begin{tabular}{@{}l}
\colorbox{white}{%
\begin{tabular}[c]{@{}l}
\texttt{mydomain.tld}
\end{tabular}
} \\
\colorbox{yellow}{%
\begin{tabular}[c]{@{}l}
\texttt{autoconfig.mydomain.tld}\\
\texttt{imap.mydomain.tld}\\
\texttt{mail.mydomain.tld}\\
\texttt{pop.mydomain.tld}\\
\texttt{smtp.mydomain.tld}
\end{tabular}
}
\end{tabular} & \texttt{aaaa:bbbb:cccc:dddd::1234} \\ \hline
% MX records
\texttt{MX} & www & \texttt{mydomain.tld} & \texttt{1 mail.mydomain.tld} \\ \hline
% NS records
\texttt{NS} & & \texttt{@} & \begin{tabular}[c]{@{}l@{}}\texttt{ns1.nameserver.tld}\\ \texttt{ns2.nameserver.tld}\end{tabular} \\ \hline
\texttt{PTR} & & \texttt{@} & \texttt{mydomain.tld} \\ \hline
% TXT for DMARC
\rowcolor{yellow} \texttt{TXT} & & \texttt{\_dmarc} & \texttt{"v=DMARC1; p=quarantine; pct=100; rua=mailto: [email protected]"} \\ \hline
% TXT for DKIM
\rowcolor{yellow} \texttt{TXT} & & \texttt{default.\_domainkey} & \texttt{"v=DKIM1; k=rsa; s=email; p=<DKIM key>"} \\ \hline
% TXT for SPF
\texttt{TXT} & & \texttt{@} & \texttt{"v=spf1 a mx ~all"} \\ \hline
% TXT for Site description
\texttt{TXT} & www & \texttt{@} & \texttt{"<description of site>"} \\ \hline
\end{tabular}
\end{table}
附言抱歉,我没搞清楚我当时是怎么想的。我只能说,当时这似乎是个好主意。
答案1
使用\cellcolor
而不是\colorbox
并因此从嵌套的 s 中删除外部填充tabular
:
\documentclass[]{article}
\usepackage[]{colortbl}
\begin{document}
\begin{table}[ht]
\centering
\caption{Caption above table.}
\begin{tabular}{|c|c|l|p{5cm}|}
\hline
% column headers
Record & Prepend & \multicolumn{1}{c|}{Name} & \multicolumn{1}{c|}{Value} \\ \hline
% A (ipv4 records)
\texttt{A} & www &
\begin{tabular}{@{}l@{}}
\cellcolor{white}%
\begin{tabular}[c]{@{}l@{}}
\texttt{mydomain.tld}
\end{tabular} \\
\cellcolor{yellow}%
\begin{tabular}[c]{@{}l@{}}
\texttt{autoconfig.mydomain.tld}\\
\texttt{imap.mydomain.tld}\\
\texttt{mail.mydomain.tld}\\
\texttt{pop.mydomain.tld}\\
\texttt{smtp.mydomain.tld}
\end{tabular}
\end{tabular} & \texttt{111.222.111.222} \\ \hline
% AAAA (ipv6) records
\texttt{AAAA} & www &
\begin{tabular}{@{}l@{}}
\cellcolor{white}%
\begin{tabular}[c]{@{}l@{}}
\texttt{mydomain.tld}
\end{tabular}
\\
\cellcolor{yellow}%
\begin{tabular}[c]{@{}l@{}}
\texttt{autoconfig.mydomain.tld}\\
\texttt{imap.mydomain.tld}\\
\texttt{mail.mydomain.tld}\\
\texttt{pop.mydomain.tld}\\
\texttt{smtp.mydomain.tld}
\end{tabular}
\end{tabular} & \texttt{aaaa:bbbb:cccc:dddd::1234} \\ \hline
% MX records
\texttt{MX} & www & \texttt{mydomain.tld} & \texttt{1 mail.mydomain.tld} \\ \hline
% NS records
\texttt{NS} & & \texttt{@} & \begin{tabular}[c]{@{}l@{}}\texttt{ns1.nameserver.tld}\\ \texttt{ns2.nameserver.tld}\end{tabular} \\ \hline
\texttt{PTR} & & \texttt{@} & \texttt{mydomain.tld} \\ \hline
% TXT for DMARC
\rowcolor{yellow} \texttt{TXT} & & \texttt{\_dmarc} & \texttt{"v=DMARC1; p=quarantine; pct=100; rua=mailto: [email protected]"} \\ \hline
% TXT for DKIM
\rowcolor{yellow} \texttt{TXT} & & \texttt{default.\_domainkey} & \texttt{"v=DKIM1; k=rsa; s=email; p=<DKIM key>"} \\ \hline
% TXT for SPF
\texttt{TXT} & & \texttt{@} & \texttt{"v=spf1 a mx ~all"} \\ \hline
% TXT for Site description
\texttt{TXT} & www & \texttt{@} & \texttt{"<description of site>"} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
正如评论中所说,你可以使用\cellcolor
,但你正在向所有表格的右侧添加空白,而不是左侧
colorbox{yellow}{%
\begin{tabular}[c]{@{}l}
\texttt{autoconfig.mydomain.tld}\\
\texttt{imap.mydomain.tld}\\
\texttt{mail.mydomain.tld}\\
\texttt{pop.mydomain.tld}\\
\texttt{smtp.mydomain.tld}
\end{tabular}
}
您避免使用 在表格左侧添加空格标记,{%
但您在表格后(但在 内\colorbox
)添加了空格,您可以使用\end{tabular}%
或通过将结束符}
放在\colorbox
之后立即添加来避免这种情况\end{tabular}
类似地,您要删除左侧的 tabcolsep 填充,但不会删除右侧的填充,@{}l
而不是@{}l@{}
作为嵌套表的序言。