
Para mostrar que a probabilidade de lançar dois dados e obter uma soma de 7 é 1/6, eu queria fazer uma tabela usando a opção "foreach" em TikZ
. O código a seguir me fornece uma tabela de todas as jogadas possíveis.
Os retângulos dos pares adjacentes se sobrepõem. Isso cria uma aparência desagradável. Como posso adicionar espaço horizontal para separar os retângulos?
Usando este código, posso substituir os retângulos contendo os seis pares de números que totalizam 7 por um círculo ou elipse?
Como posso deixar o primeiro número azul e o segundo número verde?
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,shapes,positioning,intersections,quotes,decorations.markings}
\begin{document}
\begin{tikzpicture}
\node foreach \x in {1,...,6} foreach \y in{1,...,6} [draw] at (\x-6,6-\y)
{(\x, \, \y)};
\end{tikzpicture}
\end{document}
Responder1
% arara: pdflatex
\documentclass{amsart}
\usepackage{tikz}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}[x=1.5cm,y=1.5cm]
\node foreach \x in {1,...,6} foreach \y in{1,...,6} [draw, circle] at (\x-6,6-\y)
{(\textcolor{blue}{\x}, \, \textcolor{green}{\y})};
\end{tikzpicture}
\end{document}
% arara: pdflatex
\documentclass{amsart}
\usepackage{tikz}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}[x=1.8cm,y=1cm]
\foreach \x in {1,...,6} {%
\foreach \y in {1,...,6} {%
\draw (\x-6,6-\y) ellipse (.8cm and .3cm) node {$(\textcolor{blue}{\x},\textcolor{green}{\y})$};
}
}
\end{tikzpicture}
\end{document}
Editar:
Desculpe, eu entendi errado em primeiro lugar. Olha Você aqui:
% arara: pdflatex
\documentclass{amsart}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{xifthen}
\begin{document}
\begin{tikzpicture}[x=1.8cm,y=1cm]
\foreach \x in {1,...,6} {%
\foreach \y in {1,...,6} {%
\pgfmathtruncatemacro{\test}{\x+\y};
\ifthenelse{\test=7}
{\draw (\x-6,6-\y) ellipse (.8cm and .3cm) node {$(\textcolor{blue}{\x},\textcolor{green}{\y})$};}
{\draw (\x-6,6-\y) node [draw] {$(\textcolor{blue}{\x},\textcolor{green}{\y})$};}
}
}
\end{tikzpicture}
\end{document}
Responder2
Você também pode usar uma matriz e diretivas de células vazias
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,shapes.geometric}
% shorthand for less typing
\def\mcr{\pgfmatrixcurrentrow}\def\mcc{\pgfmatrixcurrentcolumn}
\begin{document}
\begin{tikzpicture}
\matrix (a) [execute at empty cell={\ifnum7=\numexpr\mcc+\mcr\relax
\node[ellipse,draw,inner sep=1pt]
{(\textcolor{blue}{\the\mcc},\textcolor{green}{\the\mcr})};
\else
\node[draw,inner sep=1pt]{(\textcolor{blue}{\the\mcc},\textcolor{green}{\the\mcr})};
\fi}]{&&&&&\\&&&&&\\&&&&&\\&&&&&\\&&&&&\\&&&&&\\};
\end{tikzpicture}
\end{document}
Responder3
Uma tentativa com MetaPost, o mais sóbria possível. Para ser processado com LuaLaTeX.
\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
u := 1.25cm; v := -cm; pair pos; path box; picture dices;
beginfig(1);
for i = 1 upto 6:
for j = 1 upto 6:
pos := ((i+1)*u, (j+1)*v);
dices := thelabel(decimal i & ", " & decimal j, pos);
box := bbox dices;
if i+j <> 7: draw box;
else:
d1 := xpart(lrcorner box - llcorner box) + labeloffset;
d2 := ypart(urcorner box - lrcorner box) + labeloffset;
draw fullcircle xscaled d1 yscaled d2 shifted pos;
fi
draw dices;
endfor
endfor
endfig;
\end{mplibcode}
\end{document}