提问于:
浏览数:
3150
## 编译环境
操作系统
* [x] Windows 10
* [ ] macOS
* [ ] Linux
`若需勾选,请把[ ]改成[x]`
Tex发行版
* [x] TexLive `2020`
* [ ] MikTeX `版本号`
* [ ] CTeX
`若需勾选,请把[ ]改成[x]`
## 我的问题
想要实现如下效果的一种的表格:
![](https://wenda.latexstudio.net/data/attach/200527/cWDi0Xd9.jpg)
我写的过程如下:
```
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|c|c|c|>{\scriptsize}m{6cm}|}
\hline \rowcolor{yellow}
& \multicolumn{2}{c|}{\thead{Is this person \\interested \\in the news?}} & \multirowthead{2}{Where does he/she get \\most of the news \\(online, TV, etc.)?} & \multirow{2}*{\makecell{What does he/she think?\\(Write the person's name on all the responses.)}}\\
\cline{1-3} \rowcolor{yellow}
& Yes & No & & \\ \hline
\end{tabular}
\end{document}
```
编译后效果如下:
![](https://wenda.latexstudio.net/data/attach/200527/XIZ9woR4.png)
发现后一行的颜色填充命令`\rowcolor{yellow}`覆盖了前一行的表线`\cline{1-3}`以及合并的内容,请问有没有什么好的方案来解决一下这个问题,使得**表线**和**合并内容**能够正常显示?*最小工作示例已打包至附件mwe.zip(不知什么原因,附件一直处于上传中,可能无法下载附件了)。*
2 回答
1
在群里我已经发了截图给你说明了,如果非要解决的话,可以这样
```tex
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{array}
\begin{document}
\rowcolors[\Xhline{0.2pt}]{1}{yellow}{yellow}
\begin{tabular}{|c|c|c|c|>{\scriptsize}m{6cm}|}
& \multicolumn{2}{c|}{\thead{Is this person \\interested \\in the news?}} & \multirowthead{-2}{Where does he/she get \\most of the news \\(online, TV, etc.)?} & \multirow{2}*{\makecell{What does he/she think?\\(Write the person's name on all the responses.)}}\\
&Yes & No & & \\
\end{tabular}
\end{document}
```tex
-
补):非常感谢! – 2020-05-29 14:37 回复
-
显示问题需要找群主反馈一下 – OsbertWang 2020-05-27 22:50 回复
1
内容被覆盖的问题很好解决,对合并单元格的最底部使用multirowcell命令,比如`\multirowcell{-2}{...}`
cline,hline会被之后的填充命令覆盖,引用colortbl中的原文:
```text
Lines produced by \cline are coloured if you use \arrayrulecolor but you may
not notice as they are covered up by any colour pannels in the following row. This
is a ‘feature’ of \cline. If using this package you would probably better using the
- rule type in a \hhline argument, rather than \cline
```
解决这个办法是用`hhline`宏包,但是会有一些小问题,比如合并单元格之间出现空白,需要在`\hhline`再将空白的地方填上,我自己写了个[脚本](https://github.com/ZhiyuanLck/excel2tex "脚本")解决,因为需要兼容很多东西,所以对简单的例子生成的代码比较繁琐,,结果如下
![](https://wenda.latexstudio.net/data/attach/200528/pWZbeGuK.png)
由于网页显示问题,下面代码中对应的网页代码应该是&,>
```tex
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage{dashrule}
\usepackage{ehhline}
%% nested tabular
\newcommand{\minitab}[2][l]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
%% vertical line
% vertical colored line #1 color #2 width
\newcommand{\vsl}[2]{\color{#1}\vrule width #2}
% doubled vline
% #1 first color #2 first width #3 sep #4 second color #5 second sep
\newcommand{\dvsl}[5]{%
\vsl{#1}{#2}\hspace{#3}\vsl{#4}{#5}%
}
%% horizontal line
% colored solid line pattern
% #1 color #2 width #3 height
\newcommand{\hsp}[3]{\hbox{\textcolor{#1}{\rule{#2}{#3}}}}
% colored dash line pattern
% #1 color #2 width #3 height #4 style
\newcommand{\hdp}[4]{\hbox{\textcolor{#1}{\hdashrule{#2}{#3}{#4}}}}
% fill line
% #1 top fill #2 bottom fill
\newcommand{\leaderfill}[1]{%
\xleaders\hbox{%
\vbox{\baselineskip=0pt\lineskip=0pt#1}%
}\hfill%
}
% top: solid, bottom: solid
% #1 top color #2 top height #3 bottom color#4 bottom height
\newcommand{\ssfill}[4]{%
\leaderfill{\hsp{#1}{0.1pt}{#2}\hsp{#3}{0.1pt}{#4}}%
}
% top: solid, bottom: dashed
% #1 top color, #2 top height, #3 common width to expand
% #4 bottom color #5 bottom height, #6 bottom dash line style
\newcommand{\sdfill}[6]{%
\leaderfill{\hsp{#1}{#3}{#2}\hdp{#4}{#3}{#5}{#6}}%
}
% single solid
% #1 color #2 height
\newcommand{\sfill}[2]{%
\leaderfill{\hsp{#1}{0.1pt}{#2}}%
}
% single dash
% #1 color #2 width #3 height #4 style
\newcommand{\dfill}[4]{%
\leaderfill{\hdp{#1}{#2}{#3}{#4}}%
}
\definecolor{FFFF00}{HTML}{FFFF00}
\begin{document}
\begin{tabular}{*{5}{c}}
\hhline{
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
}
% row 1
\multicolumn{1}{!{\vsl{black}{0.4pt}}c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{2}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
\\
\hhline{
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
}
% row 2
\multicolumn{1}{!{\vsl{black}{0.4pt}}c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{2}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
\\
\hhline{
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0pt}}
!{\sfill{FFFF00}{0pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0pt}}
>{\vsl{black}{0.4pt}}
}
% row 3
\multicolumn{1}{!{\vsl{black}{0.4pt}}c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{2}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}
\multirow{-3}*{\minitab[c]{\minitab[c]{Is this person \\interested \\in the news?}}}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}}
\\
\hhline{
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{FFFF00}{0.4pt}}
>{\vsl{black}{0.4pt}}
}
% row 4
\multicolumn{1}{!{\vsl{black}{0.4pt}}c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}
\multirow{-4}*{}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}Yes}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}No}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}
\multirow{-4}*{\minitab[c]{\minitab[c]{Where does he/she get \\most of the news \\(online, TV, etc.)?}}}}
& \multicolumn{1}{c!{\vsl{black}{0.4pt}}}{\cellcolor{FFFF00}
\multirow{-4}*{\minitab[c]{\minitab[c]{What does he/she think? \\(Write the person’s name on all the responses.)}}}}
\\
\hhline{
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
!{\sfill{black}{0.4pt}}
>{\vsl{black}{0.4pt}}
}
\end{tabular}
\end{document}
```
你的回答
请登录后回答
你的回答将会帮助更多人,请务必认真回答问题。