我已经问过了问题昨天,希望自己做一下,但是无法取得好结果。
我想将表格中单个单元格的垂直线和水平线设置为自定义粗细。此外,自定义粗细线应相对于所有正常线居中。
这就是我现在正在使用的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength{\doublerulesep}{0pt}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm
\begin{document}
\begin{center}
\begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} |}
\hline
A & B & C, D & E & F & G \tabularnewline \hline
0 & 1 & 2 & 3 & 4 & 3 \tabularnewline \hline
1 & \multicolumn{1}{c||}{3} & \multicolumn{1}{|c|}{3} & 4 & 5 & 3 \tabularnewline \hhline{~~-~~~}\hhline{------}\hhline{~~-~~~}
2 & 3 & \multicolumn{1}{c||}{4} & \multicolumn{1}{|c|}{5} & 6 & 3 \tabularnewline \hline
3 & 4 & 5 & 6 & 7 & 3 \tabularnewline \hline
4 & 5 & 6 & 7 & 8 & 3 \tabularnewline \hline
5 & 6 & 7 & 8 & 9 & 3 \tabularnewline \hline
\end{tabular}
\end{center}
\end{document}
答案1
这两个\hhline{~~-~~~}
增加了第三排和第四排之间的空间
您可以通过添加两个负空间来删除这两个空格\noalign{\vskip-0.4pt}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm
\setlength{\doublerulesep}{0pt}
\begin{document}
\begin{center}
\begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} |}
\hline
A & B & C, D & E & F & G \tabularnewline \hline
0 & 1 & 2 & 3 & 4 & 3 \tabularnewline \hline
1 & \multicolumn{1}{c||}{3} & \multicolumn{1}{|c|}{3} & 4 & 5 & 3 \tabularnewline
\noalign{\vskip-0.4pt} % <- add this
\hhline{~~-~~~}\hhline{------}\hhline{~~-~~~}
\noalign{\vskip-0.4pt} % and this
2 & 3 & \multicolumn{1}{c||}{4} & \multicolumn{1}{|c|}{5} & 6 & 3 \tabularnewline \hline
3 & 4 & 5 & 6 & 7 & 3 \tabularnewline \hline
4 & 5 & 6 & 7 & 8 & 3 \tabularnewline \hline
5 & 6 & 7 & 8 & 9 & 3 \tabularnewline \hline
\end{tabular}
\end{center}
\end{document}
答案2
表格如matrix
TikZ 图片所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes = {draw, text width=0.1*\textwidth, minimum height=4ex,
align=center, anchor=center, outer sep=0pt},
column sep = -\pgflinewidth,
row sep = -\pgflinewidth,
column 2/.style = {nodes={text width=0.2*\textwidth}},
column 3/.style = {nodes={text width=0.2*\textwidth}},
]
{
A & B & C, D & E & F & G \\
0 & 1 & 2 & 3 & 4 & 3 \\
1 & 3 & 3 & 4 & 5 & 3 \\
2 & 3 & 4 & 5 & 6 & 3 \\
3 & 4 & 5 & 6 & 7 & 3 \\
4 & 5 & 6 & 7 & 8 & 3 \\
5 & 6 & 7 & 8 & 9 & 3 \\
};
\draw[ultra thick]
(m-3-3.north west) |- (m-3-3.south east) -- (m-4-3.south east);
\end{tikzpicture}
\end{center}
\end{document}
或者你的意思是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes = {draw, text width=0.1*\textwidth, minimum height=4ex,
align=center, anchor=center, outer sep=0pt},
column sep = -\pgflinewidth,
row sep = -\pgflinewidth,
column 2/.style = {nodes={text width=0.2*\textwidth}},
column 3/.style = {nodes={text width=0.2*\textwidth}},
]
{
A & B & C, D & E & F & G \\
0 & 1 & 2 & 3 & 4 & 3 \\
1 & 3 & 3 & 4 & 5 & 3 \\
2 & 3 & 4 & 5 & 6 & 3 \\
3 & 4 & 5 & 6 & 7 & 3 \\
4 & 5 & 6 & 7 & 8 & 3 \\
5 & 6 & 7 & 8 & 9 & 3 \\
};
\draw[ultra thick]
(m-3-3.north west) |- (m-3-3.south east) |- cycle;
\end{tikzpicture}
\end{center}
\end{document}
答案3
另一种策略是pstricks
:我在表格\hline
s 的相关位置插入空节点,并用 连接它们\pslines
。为此,我定义了一个\addpnode
带有三个参数的命令:与表格左侧的距离(不包括\tabcolsep
s 和垂直规则的厚度)、插入节点的列号以及节点的名称。此命令适用于具有规定宽度的列。
这会得到以下简短的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength{\doublerulesep}{0.8pt}
\usepackage{boldline, makecell}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm
\usepackage{pst-node}
\usepackage{auto-pst-pdf}
\newcommand*{\addpnode}[3]{\noalign{\rlap{\pnode[\dimexpr#1+#2\tabcolsep*2+0.5\arrayrulewidth+#2\arrayrulewidth\relax, -0.5\arrayrulewidth]{#3}}}}
\begin{document}
\begin{center}
\begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | *{3}{>{\centering\arraybackslash}m{0.1\textwidth} |}}
\hline
A & B & C, D & E & F & G \\
\addpnode{0.1\textwidth}{1}{K}
\hline
0 & 1 & 2 & 3 & 4 & 3 \\
\addpnode{0.1\textwidth}{1}{A}\addpnode{0.3\textwidth}{2}{A1}\hline
1 & 3 & 3 & 4 & 5 & 3 \\
\addpnode{0.3\textwidth}{2}{B} \addpnode{0.5\textwidth}{3}{B1}\hline
2 & 3 & 4 & 5 & 6 & 3 \\
\addpnode{0.5\textwidth}{3}{C}\addpnode{0.6\textwidth}{4}{C1} \hline
3 & 4 & 5 & 6 & 7 & 3 \\
\addpnode{0.6\textwidth}{4}{D} \addpnode{0.7\textwidth}{5}{D1}\hline
4 & 5 & 6 & 7 & 8 & 3 \\
\addpnode{0.7\textwidth}{5}{E} \addpnode{0.8\textwidth}{6}{E1}\hline
5 & 6 & 7 & 8 & 9 & 3 \\
\addpnode{0.8\textwidth}{6}{F}\hline
\end{tabular}
\psline[linewidth=1.2pt, linecolor=red](A)(A1)(B)(B1)(C)(C1)(D)(D1)(E)(E1)(F)
\end{center}
\end{document}