这是 MWE(我将 MikTeX 2.9 与 TeXworks 结合使用):
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{a4paper, portrait, left=2cm, right=2cm, top=3cm, bottom=3cm}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline}
\begin{document}
\thispagestyle{empty}
\definecolor{tch}{gray}{0.4}
\definecolor{tc3}{gray}{0.85}
\definecolor{tc4}{gray}{0.80}
\newcommand{\hlc}[1]{\cellcolor{tc3}\centering{}#1}
\newcommand{\hld}[1]{\cellcolor{tc4}\centering{}#1}
\newcommand{\hldx}[1]{\cellcolor{tc4}#1}
\newcommand{\hc}{\cellcolor{tc3}\ }
\newcommand{\hd}{\cellcolor{tc4}\ }
\setlength\arrayrulewidth{1pt}
\begin{tabular}{%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright\arraybackslash}p{11em}!{\color{white}\vrule width 0.8pt}%
}
\arrayrulecolor{white}\hline\rowcolor{tch}
\color{white}{\bf Left preamp} &
\color{white}{\bf Right preamp} &
\color{white}{\bf Wiring} &
\color{white}{\bf Description} \\
\hld{AUDIO-L\\(O)} &\hlc &\hld{25\,cm (10\,in) shielded}&\hldx{Voice output x}\\
\hline
\hld{AGC-L\\(O)} &\hlc &\hld{15\,cm (6\,in) shielded}&\hldx{Voice output y}\\
\hline
\hld{EXC-L\\(O)} &\hld{abcd\\(I)} &\hld{20\,cm (8\,in) shielded}&\hldx{Voice output z}\\
\hline
\hlc &\hlc &\hld{25\,cm (10\,in) shielded}&\hd\\
\hhline{=--~}
\hlc &\hlc &\hld{25\,cm (10\,in) shielded}&\multirow{-2}={\hldx{Excitation signals for both sides of the xyz}} \\
\hline
\end{tabular}
\end{document}
结果如下:
我不指望双水平线超出第一列。使用\hhline{=--~}
只是为了更好地进行可视化。我实际上想使用的是\hline{---~}
。\cline
在这种情况下根本不起作用(没有显示任何线)。我如何确保我的多行单元格不会被线划伤?
与我的主要问题无关,我不知道标题文本上方的额外空间来自哪里。
答案1
使穿过multirow
单元格的线不可见的一种方法是给它着色:
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{a4paper, portrait, hmargin=2cm, vmargin=3cm}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline}
\begin{document}
\thispagestyle{empty}
\definecolor{tch}{gray}{0.4}
\definecolor{tc3}{gray}{0.85}
\definecolor{tc4}{gray}{0.80}
\newcommand{\hlc}[1]{\cellcolor{tc3}\centering{}#1}
\newcommand{\hld}[1]{\cellcolor{tc4}\centering{}#1}
\newcommand{\hldx}[1]{\cellcolor{tc4}#1}
\newcommand{\hc}{\cellcolor{tc3}\ }
\newcommand{\hd}{\cellcolor{tc4}\ }
\setlength\arrayrulewidth{1pt}
\begin{tabular}{%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright}p{7.5em}!{\color{white}\vrule width 0.8pt}%
>{\raggedright\arraybackslash}p{11em}%
}
\arrayrulecolor{white}\hline\rowcolor{tch}
\color{white}{\bf Left preamp} &
\color{white}{\bf Right preamp} &
\color{white}{\bf Wiring} &
\color{white}{\bf Description} \\
\hld{AUDIO-L\\(O)} &\hlc &\hld{25\,cm (10\,in) shielded}&\hldx{Voice output x}\\
\hline
\hld{AGC-L\\(O)} &\hlc &\hld{15\,cm (6\,in) shielded}&\hldx{Voice output y}\\
\hline
\hld{EXC-L\\(O)} &\hld{abcd\\(I)} &\hld{20\,cm (8\,in) shielded}&\hldx{Voice output z}\\
\hline
\hlc &\hlc &\hld{25\,cm (10\,in) shielded}&\hd\\
\hhline{--->{\arrayrulecolor{tc4}}-} % <---
\hlc &\hlc &\hld{25\,cm (10\,in) shielded} &\multirow{-2}={\hldx{Excitation signals for both sides of the xyz}} \\
\hline
\end{tabular}
\end{document}
编辑:
如果您希望最后两行之间的线条更粗(如您在问题图像中所示,那么您应该将其更改\hhline{=--~}
为
\hhline{--->{\arrayrulecolor{tc4}\doublerulesepcolor{tc4}}=} % <---
而不是\hhline{--->{\arrayrulecolor{tc4}}-} % <---
上面的 mwe。你将获得:
答案2
诀窍是绘制一个完整的hhline
,最后一段是背景颜色。我借此机会用命令简化了您的代码\columncolor
。第一行中不需要的垂直间距可以通过\thead
以下命令解决makecell
:
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{a4paper, portrait, left=2cm, right=2cm, top=3cm, bottom=3cm}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{makecell}
\begin{document}
\thispagestyle{empty}
\definecolor{tch}{gray}{0.4}
\definecolor{tc3}{gray}{0.85}
\definecolor{tc4}{gray}{0.80}
\newcommand{\hlc}[1]{\cellcolor{tc3}\centering{}#1}
\setlength\arrayrulewidth{1pt}
\setlength{\extrarowheight}{2pt}
\renewcommand{\theadfont}{\raggedright\normalsize\bfseries\color{white}}
\renewcommand{\theadalign}{l}
\begin{tabular}{
*{3}{>{\columncolor{tc4}\centering}p{7.5em}!{\color{white}\vrule width 0.8pt}}%
>{\columncolor{tc4}\raggedright\arraybackslash}p{11em}!{\color{white}\vrule width 0.8pt}%
}
\arrayrulecolor{white}\hline\rowcolor{tch}
\thead{Left preamp }&
\thead{Right preamp} &
\thead{Wiring} &
\thead{Description} \\
AUDIO-L\\(O) &\hlc & 25\,cm (10\,in) shielded & Voice output x \\
\hline
AGC-L\\(O) &\hlc & 15\,cm (6\,in) shielded & Voice output y \\
\hline
EXC-L\\(O) & abcd\\(I) & 20\,cm (8\,in) shielded & Voice output z \\
\hline
\hlc &\hlc & 25\,cm (10\,in) shielded & \\
\hhline{---|>{\arrayrulecolor{tc4}}->{\arrayrulecolor{white}}}
\hlc &\hlc & 25\,cm (10\,in) shielded & \multirow{-2}={Excitation signals for both sides of the xyz} \\
\hline
\end{tabular}
\end{document}
答案3
{NiceTabular}
供参考,这里有一个使用创建表格的简单方法nicematrix
。
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{a4paper, portrait, left=2cm, right=2cm, top=3cm, bottom=3cm}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}
[hvlines-except-borders,rules={color=white,width=1pt}]
{ccm[l]{7.5em}p[l]{11em}}
\CodeBefore
\rowcolor[gray]{0.4}{1}
\cellcolor[gray]{0.85}{2-2,3-2,5-1,5-2,6-1,6-2}
\rectanglecolor[gray]{0.80}{2-1}{4-1}
\cellcolor[gray]{0.80}{4-2}
\rectanglecolor[gray]{0.80}{2-3}{6-4}
\Body
\RowStyle[color=white]{\sffamily\bfseries}
Left preamp & Right preamp & Wiring & Description \\
\Block{}{AUDIO-L\\(O)} & & 25\,cm (10\,in) shielded & Voice output x \\
\Block{}{AGC-L\\(O)} & & 15\,cm (6\,in) shielded & Voice output y \\
\Block{}{EXC-L\\(O)} & \Block{}{abcd\\(I)} & 20\,cm (8\,in) shielded & Voice output z \\
& & 25\,cm (10\,in) shielded
& \Block{2-1}{Excitation signals for both sides of the xyz} \\
& & 25\,cm (10\,in) shielded \\
\end{NiceTabular}
\end{document}