我需要multirow
在下表中合并内容,但总是遇到错误。我发现以下示例是一个格式很好的表格,带有彩色单元格和圆角这里。
我已尝试在自己的表中实现它,您将在此看到它MWE
。
\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
\begin{document}
\begin{tikzpicture}
\clip node (m) [matrix,matrix of nodes,
fill=black!20,inner sep=0pt,
nodes in empty cells,
nodes={minimum height=1cm,minimum width=2.6cm,anchor=center,outer sep=0,font=\sffamily},
row 1/.style={nodes={fill=black,text=white}},
column 1/.style={nodes={fill=gray,text=white,align=right,text width=2.5cm,text depth=0.5ex}},
column 2/.style={text width=4cm,align=center,every even row/.style={nodes={fill=white}}},
%column 3/.style={text width=3cm,align=center,every even row/.style={nodes={fill=white}},},
row 1 column 1/.style={nodes={fill=gray}},
prefix after command={[rounded corners=4mm] (m.north east) rectangle (m.south west)}
] {
& Things Identified \\
1 & \\
2 & A \\
3 & B\\
3 & C\\
4 & D \\
4 & E \\
4 & F \\
5 & G\\
5 & H\\
};
\end{tikzpicture}
}
\end{document}
这MWE
为我提供了以下结果:
当我尝试使用multirow
以便不在第 1 列中重复类别名称时,我的演示文稿无法编译。
以下是MWE
我尝试实现的代码multirow
:
UPDATE:
\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1]
at (#2)
{#3};
}
\begin{document}
\begin{frame}
\begin{adjustbox}{max totalsize={1.2\textwidth}{0.8\textheight},center}
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m)
[
matrix,
matrix of nodes,
fill=black!20,
inner sep=0pt,
nodes in empty cells,
nodes={
minimum height=1cm,
minimum width=2.6cm,
anchor=center,
outer sep=0,
font=\sffamily
},
row 1/.style={
nodes={fill=black,text=white}
},
column 1/.style={
nodes={
fill=gray,
text=white,
align=right,
text width=2.5cm,
text depth=0.5ex}
},
column 2/.style={
text width=4cm,
align=center,
every even row/.style={nodes={fill=white}}
},
column 3/.style={
text width=3cm,
align=center,
every even row/.style={nodes={fill=white}}
},
row 1 column 1/.style={nodes={fill=gray}},
prefix after command={
[rounded corners=4mm]
(m.north east) rectangle (m.south west)
}
]
{
\& Things Identified \\
1 \& \\
2 \& A \\
\& B \\
\& C \\
\& D \\
\& E \\
\& F \\
\& G \\
\& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
\draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-2.south east);
\end{tikzpicture}
\end{adjustbox}
\end{frame}
\end{document}
在使用 调整框的大小后\usepackageadjustbox
,如上面更新的代码所示,并实施@Gonzalo Medina 提案,我遇到的问题在于浅灰色框仍然显示在列中multirow
,如下所示:
我不确定这是因为这些盒子彼此“重叠”还是由于其他原因,但我们如何才能消除(或覆盖它们)呢?
答案1
这是一种可能性;包\multirow
中的命令multirow
在这里没有用,因为 TikZ 矩阵实际上不是标准的 LaTeX 矩阵;您可以使用某些矩阵单元的锚点将标签放置在所需位置(定义一个命令来执行此操作,如我的示例代码中所示)。我还画了一些水平线来分隔行组(否则,多行标签将无法快速读取)。矩阵的尺寸太大,无法放入,frame
因此我shrink
仅将该选项用于示例(如果可能,最好的替代方法是减小尺寸):
\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1]
at (#2)
{#3};
}
\begin{document}
\begin{frame}[shrink=15]
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m)
[
matrix,
matrix of nodes,
fill=black!20,
inner sep=0pt,
nodes in empty cells,
nodes={
minimum height=1cm,
minimum width=2.6cm,
anchor=center,
outer sep=0,
font=\sffamily
},
row 1/.style={
nodes={fill=black,text=white}
},
column 1/.style={
nodes={
fill=gray,
text=white,
align=right,
text width=2.5cm,
text depth=0.5ex}
},
column 2/.style={
text width=4cm,
align=center,
every even row/.style={nodes={fill=white}}
},
column 3/.style={
text width=3cm,
align=center,
every even row/.style={nodes={fill=white}}
},
row 1 column 1/.style={nodes={fill=gray}},
prefix after command={
[rounded corners=4mm]
(m.north east) rectangle (m.south west)
}
]
{
\& \& Things Identified \\
1 \& \& \\
2 \& \& A \\
\& \& B \\
\& \& C \\
\& \& D \\
\& \& E \\
\& \& F \\
\& \& G \\
\& \& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
\draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-3.south east);
\end{tikzpicture}
\end{frame}
\end{document}
更新:
\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1]
at (#2)
{#3};
}
\begin{document}
\begin{frame}[shrink=15]
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m)
[
matrix,
matrix of nodes,
fill=black!20,
inner sep=0pt,
nodes in empty cells,
nodes={
minimum height=1cm,
minimum width=2.6cm,
anchor=center,
outer sep=0,
font=\sffamily
},
row 1/.style={
nodes={fill=black,text=white}
},
column 1/.style={
nodes={
fill=gray,
text=white,
align=right,
text width=2.5cm,
text depth=0.5ex}
},
column 2/.style={
text width=4cm,
align=center,
every even row/.style={nodes={fill=white}}
},
column 3/.style={
text width=3cm,
align=center,
every even row/.style={nodes={fill=white}}
},
row 1 column 1/.style={nodes={fill=gray}},
prefix after command={
[rounded corners=4mm]
(m.north east) rectangle (m.south west)
}
]
{
\& Things Identified \\
1 \& \\
2 \& A \\
\& B \\
\& C \\
\& D \\
\& E \\
\& F \\
\& G \\
\& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
\draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-2.south east);
\end{tikzpicture}
\end{frame}
\end{document}