![关于 tikz 图片分辨率的疑问](https://linux22.com/image/398433/%E5%85%B3%E4%BA%8E%20tikz%20%E5%9B%BE%E7%89%87%E5%88%86%E8%BE%A8%E7%8E%87%E7%9A%84%E7%96%91%E9%97%AE.png)
因此,我有以下代码:
感谢@Marmot
\documentclass{article}
\usepackage{multirow}
\usepackage{color}
\usepackage{layout}
\usepackage{multicol}
\usepackage{subcaption}
\usepackage{caption}
\usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{table}
\parbox{.45\linewidth}{
\centering
\begin{tikzpicture}[local cs/.style={shift={(#1.south west)},x={(#1.south
east)-(#1.south west)},y={(#1.north west)-(#1.south west)}}]
\node[inner sep=0pt,outer sep=0pt] (tab) {\begin{tabular}{|c|c|c|c|c|c|}
\hline
& & & & & \\ \hline
& & & & & \\ \hline
& & & & & \\ \hline
& & & & & \\ \hline
& & & & & \\ \hline
& & & & & \cellcolor{gray!25} \\ \hline
& & & & & \cellcolor{gray!25} \\ \hline
& & & & & \cellcolor{gray!25} \\ \hline
& & & & & \cellcolor{gray!25} \\ \hline
\end{tabular}};
\begin{scope}[local cs=tab,font=\sffamily,nodes={align=center}]
\draw[thick,latex-latex] ([yshift=-1em]0,0)
-- ([yshift=-1em]1,0) node[pos=5/12,below]{independent\\
variables} node[pos=5/6,anchor=north west]{dependent\\
variables};
\draw[double=black,double distance=0.8pt,white,thick] (5/6,-0.2em)
-- ++(0,-1.6em);
\draw[thick,latex-latex] ([xshift=1em]1,0) -- ([xshift=1em]1,1)
node[pos=2/9,right]{test\\rows}
node[pos=13/18,right]{training\\rows};
\draw[double=black,double distance=0.8pt,white,thick]
([xshift=0.2em]1,4/9) -- ++ (1.6em,0);
\end{scope}
\end{tikzpicture}
}
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tikzpicture}[local cs/.style={shift={(#1.south west)},x={(#1.south
east)-(#1.south west)},y={(#1.north west)-(#1.south west)}}]
\node[inner sep=0pt,outer sep=0pt] (tab) {\begin{tabular}{|c|c|c|c|c|c|}
\hline
& &\cellcolor{gray!25} & & & \cellcolor{gray!25} \\ \hline
&\cellcolor{gray!25} & & & &\cellcolor{gray!25} \\ \hline
& & & & & \\ \hline
& \cellcolor{gray!25} & & & & \\ \hline
& & & & \cellcolor{gray!25} & \\ \hline
& &\cellcolor{gray!25} & & & \\ \hline
\cellcolor{gray!25} & & & & & \\ \hline
& \cellcolor{gray!25} & & & & \\ \hline
& & & \cellcolor{gray!25} & &\cellcolor{gray!25} \\ \hline
\end{tabular}};
\begin{scope}[local cs=tab,font=\sffamily,nodes={align=center}]
\draw[thick,latex-latex] ([yshift=-1em]0,0)
-- ([yshift=-1em]1,0) node[pos=1/2,below]{no demarcation between
independent\\ and dependent variables};
\draw[thick,latex-latex] ([xshift=1em]1,0) -- ([xshift=1em]1,1)
node[pos=1/2,right]{no\\ demarcation\\ between\\ training and\\ test rows};
\end{scope}
\end{tikzpicture}
}
\end{table}
\end{document}
如果你没有任何东西可以与之比较,你会说一旦代码在 LateX 中编译,它们看起来就很棒。然而,我遇到了这个立方体,它具有更高的清晰度/分辨率,并且它也是用 tikZ 创建的。这怎么可能发生?有没有选项可以设置分辨率?
更新。现在我正在使用@Marmot 的新代码,我可以截取屏幕截图进行比较。实际上,它们(即浅蓝色)并不相同,立方体稍微亮一些(单元格编号为 5):
答案1
这将使用 重新绘制您的表格tikz
。线宽设置为非常细,并且代码中的相关位置已标记。我不知道这是否与立方体中的线宽相同。您知道其代码的位置吗?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc,fit}
\makeatletter
\long\def\ifnodedefined#1#2#3{%
\@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
\tikzset{matrix vlines/.style={execute at end matrix={
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\xdef\FitList{}
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-col-\XX) {};
}
\foreach \XX in {2,...,\the\pgf@matrix@numberofcolumns}
{\draw[#1] ($(\tikzmatrixname-col-\XX.west)!0.5!(\tikzmatrixname-col-\the\numexpr\XX-1\relax.east)$)
coordinate (aux) (aux|-\tikzmatrixname.north)
-- (aux|-\tikzmatrixname.south);
}
}},matrix hlines/.style={execute at end matrix={
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\xdef\FitList{}
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-row-\YY) {};
}
\foreach \XX in {2,...,\the\pgfmatrixcurrentrow}
{\draw[#1] ($(\tikzmatrixname-row-\XX)!0.5!(\tikzmatrixname-row-\the\numexpr\XX-1\relax)$)
coordinate (aux) (aux-|\tikzmatrixname.west)
-- (aux-|\tikzmatrixname.east);
}
}},
matrix dividers/.style={matrix vlines=#1,matrix hlines=#1},
matrix frame/.style={execute at end matrix={
\draw[#1] (\tikz@[email protected] west) rectangle (\tikz@[email protected] east);
}}}
\makeatother
\definecolor{myblue}{RGB}{176, 170, 247}
\begin{document}
\begin{table}
\tikzset{local cs/.style={shift={(#1.south west)},x={(#1.south
east)-(#1.south west)},y={(#1.north west)-(#1.south west)}},
my mat/.style={matrix of nodes,nodes in empty cells,
inner sep=0pt,outer sep=0pt,column sep=-\pgflinewidth/2,
row sep=-\pgflinewidth/2,ampersand replacement=\&,
matrix dividers=very thin,%<-
matrix frame=very thin,%<-
cells={nodes={minimum width=1.33em,minimum height=1.33em}}},
cc/.style={fill=#1},cc/.default=myblue}
\parbox{.45\linewidth}{
\centering
\begin{tikzpicture}
\matrix[my mat]
(tab) {
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& |[cc]| \\
\& \& \& \& \& |[cc]| \\
\& \& \& \& \& |[cc]| \\
\& \& \& \& \& |[cc]| \\
};
\begin{scope}[local cs=tab,font=\sffamily,nodes={align=center}]
\draw[thick,latex-latex] ([yshift=-1em]0,0)
-- ([yshift=-1em]1,0) node[pos=5/12,below]{independent\\
variables} node[pos=5/6,anchor=north west]{dependent\\
variables};
\draw[double=black,double distance=0.8pt,white,thick] (5/6,-0.2em)
-- ++(0,-1.6em);
\draw[thick,latex-latex] ([xshift=1em]1,0) -- ([xshift=1em]1,1)
node[pos=2/9,right]{test\\rows}
node[pos=13/18,right]{training\\rows};
\draw[double=black,double distance=0.8pt,white,thick]
([xshift=0.2em]1,4/9) -- ++ (1.6em,0);
\end{scope}
\end{tikzpicture}
}
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tikzpicture}[local cs/.style={shift={(#1.south west)},x={(#1.south
east)-(#1.south west)},y={(#1.north west)-(#1.south west)}}]
\matrix[my mat]
(tab) {
\& \&|[cc]| \& \& \& |[cc]| \\
\&|[cc]| \& \& \& \&|[cc]| \\
\& \& \& \& \& \\
\& |[cc]| \& |[cc=red]| \& \& \& \\
\& \& \& \& |[cc]| \& \\
\& \&|[cc]| \& \& \& \\
|[cc]| \& \& \& \& \& \\
\& |[cc]| \& \& \& \& \\
\& \& \& |[cc]| \& \&|[cc]| \\
};
\begin{scope}[local cs=tab,font=\sffamily,nodes={align=center}]
\draw[thick,latex-latex] ([yshift=-1em]0,0)
-- ([yshift=-1em]1,0) node[pos=1/2,below]{no demarcation between
independent\\ and dependent variables};
\draw[thick,latex-latex] ([xshift=1em]1,0) -- ([xshift=1em]1,1)
node[pos=1/2,right]{no\\ demarcation\\ between\\ training and\\ test rows};
\end{scope}
\end{tikzpicture}
}
\end{table}
\end{document}