
TikZ를 사용하여 이와 같은 그림을 그리는 방법은 무엇입니까?
다음 예제를 시도했지만 셀 윤곽선(테두리)을 그리는 방법을 알 수 없었습니다.
\documentclass[12pt,a4paper]{article}
\usepackage[left=0cm,right=0cm,top=0cm,bottom=0cm]{geometry}
\usepackage{tikz}
\usepackage{collcell}
\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1}%
\newcommand{\ApplyGradient}[1]{%
\pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}
\hspace{-0.33em}\colorbox{red!\PercentColor!black}{}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{10mm} % box size
\setlength{\tabcolsep}{0pt}
\begin{document}
\begin{table}[ht]
\begin{center}
\begin{tabular}{*{12}{R}}
0.03 & 0.34 & 0.41 & 0.25 & 0.89 & 0.49 & 0.79 & 0.83 & 0.82 & 0.94 & 0.34 & 0.41 \\
0.49 & 0.25 & 0.80 & 0.83 & 0.93 & 0.25 & 0.82 & 0.80 & 0.35 & 0.00 & 0.25 & 0.80 \\
0.21 & 0.13 & 0.53 & 0.07 & 1.00 & 0.66 & 0.07 & 0.18 & 0.73 & 0.05 & 0.13 & 0.53 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.23 & 0.31 & 0.90 & 0.03 & 0.18 & 0.60 & 0.49 & 0.02 & 0.44 & 0.50 & 0.31 & 0.90 \\
0.40 & 0.91 & 0.84 & 0.88 & 0.04 & 0.59 & 0.75 & 0.91 & 0.69 & 0.88 & 0.91 & 0.84 \\
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\
0.07 & 0.44 & 0.65 & 0.46 & 0.65 & 0.75 & 0.80 & 0.56 & 0.89 & 0.50 & 0.44 & 0.65 \\
\end{tabular}
\end{center}
\end{table}
\end{document}
답변1
matrix
저는 이것을 그리기 위해 TikZ를 사용할 것입니다 .
암호
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix(m)[matrix of nodes,nodes in empty cells,
nodes={inner sep=20pt,draw={green!20!yellow},line width=2pt},
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
]{
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
&&&&&&&&&&&\\
};
\begin{scope}[on background layer]
\foreach \i in {1,...,12} \foreach \j in {1,...,12}{
\pgfmathrandominteger\x{10}{70}
\node[fill=black!\x!white,inner sep=20pt]at(m-\i-\j){};
}
\end{scope}
\end{tikzpicture}
\end{document}
산출
답변2
이것은 색상을 넣기 위해 Kevin C의 아이디어를 사용하지만 matrix
.
\documentclass[border=2pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
%% draw the color boxes
\foreach \i in {0.5,...,11.5} {
\foreach \j in {0.5,...,11.5}{
\pgfmathrandominteger\x{10}{70}
\node[fill=black!\x!white,inner sep=0pt,minimum width=1cm,minimum height=1cm]at(\i,\j){};
}
}
%% draw the borders
\foreach \x in {0,1,...,12}{
\draw[green!20!yellow,line width=2pt] (\x,0) -- (\x,12);
}
\foreach \y in {0,1,...,12}{
\draw[green!20!yellow,line width=2pt] (0,\y) -- (12,\y);
}
\end{tikzpicture}
\end{document}
키 스트로크를 더 줄일 수도 있었지만 그대로 두었습니다.
수정 구슬 참여:
OP(답변으로 게시됨)의 코드를 사용하면 s를 \begin{tabular}{|*{12}{R|}}
통해 수직선을 추가하고 수평선을 추가해야 합니다 \hline
. F 선의 색상을 변경하고 로드 colortbl
하고 발행합니다 \arrayrulecolor{green}
. 또한 내용이 페이지 밖으로 나가지 않도록 \fboxsep
를 변경했습니다 . s 8mm
의 경우 table
나는 항상 \centering
over를 선호합니다 \begin{center}
.
전체 코드:
\documentclass[12pt,a4paper]{article}
\usepackage[left=0cm,right=0cm,top=0cm,bottom=0cm]{geometry}
\usepackage{tikz}
\usepackage{collcell,colortbl}
\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1}%
\newcommand{\ApplyGradient}[1]{%
\pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}
\hspace{-0.33em}\colorbox{red!\PercentColor!black}{}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}c<{\endcollectcell}}
\renewcommand{\arraystretch}{0}
\setlength{\fboxsep}{8mm} % box size
\setlength{\tabcolsep}{0pt}
\setlength{\arrayrulewidth}{2pt}
\arrayrulecolor{green}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|*{12}{R|}}\hline
0.03 & 0.34 & 0.41 & 0.25 & 0.89 & 0.49 & 0.79 & 0.83 & 0.82 & 0.94 & 0.34 & 0.41 \\\hline
0.49 & 0.25 & 0.80 & 0.83 & 0.93 & 0.25 & 0.82 & 0.80 & 0.35 & 0.00 & 0.25 & 0.80 \\\hline
0.21 & 0.13 & 0.53 & 0.07 & 1.00 & 0.66 & 0.07 & 0.18 & 0.73 & 0.05 & 0.13 & 0.53 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.23 & 0.31 & 0.90 & 0.03 & 0.18 & 0.60 & 0.49 & 0.02 & 0.44 & 0.50 & 0.31 & 0.90 \\\hline
0.40 & 0.91 & 0.84 & 0.88 & 0.04 & 0.59 & 0.75 & 0.91 & 0.69 & 0.88 & 0.91 & 0.84 \\\hline
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\\hline
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.36 & 0.12 & 0.92 & 0.73 & 0.12 & 0.58 & 0.42 & 0.89 & 0.15 & 0.50 & 0.12 & 0.92 \\\hline
0.93 & 0.07 & 0.57 & 0.43 & 0.12 & 0.70 & 0.54 & 0.25 & 0.06 & 0.57 & 0.07 & 0.57 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.81 & 0.49 & 0.27 & 0.07 & 0.57 & 0.12 & 0.26 & 0.39 & 0.57 & 0.80 & 0.49 & 0.27 \\\hline
0.09 & 0.98 & 0.46 & 0.83 & 0.69 & 0.56 & 0.08 & 0.77 & 0.40 & 0.88 & 0.98 & 0.46 \\\hline
0.07 & 0.44 & 0.65 & 0.46 & 0.65 & 0.75 & 0.80 & 0.56 & 0.89 & 0.50 & 0.44 & 0.65 \\\hline
\end{tabular}
\end{table}
\end{document}
답변3
정확한 요구 사항에 따라 다음과 같이 충분할 수 있습니다.
\documentclass[tikz,border=0.125cm]{standalone}
\begin{document}
\tikz\foreach \i in {0,...,9}
\foreach \j [evaluate={\k=rnd*75;}] in {0,...,9}
\filldraw [fill=gray!\k, draw=green!50!brown, ultra thick]
(\j,\i) rectangle +(1, 1);
\end{document}