\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\r{2}
\foreach \c [count=\i from 0] in {
$\overline{1}$,
$\overline{3}$,
$2$,
$1$,
$3$,
$\overline{2}$}
{
\path (0,0) -- (60*\i:\r) node[circle,inner sep=1mm,fill=black](\i){} --++ (60*\i:10pt) node{\c};
}
\foreach \i in {0,...,5}
\foreach \n in {\i,...,5}
\draw (\i.center) -- (\n.center);
\end{tikzpicture}
\end{document}
我想将由 $(2,\overline{2})$、$(1,\overline{1})$ 和 $(3,\overline{3})$ 确定的直径变为红色(如上图所示)。我不确定该怎么做。我希望图中的其他边保持黑色。
答案1
像这样:
笔记:您的代码片段没有产生显示图像
只需要在黑色和红色部分的顶点之间分开画线即可:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1.5pt},
every label/.style={inner sep=0pt}]
\newdimen\R
\R=1.3cm
\draw
(60:\R) \foreach \x in {120,180,...,300} { -- (\x:\R) };
\draw[red]
(300:\R) \foreach \x in {360,60} { -- (\x:\R) };
\foreach \i [count=\j] in { \overline{3},2,1,3,\overline{2},\overline{1} }
{
\node[dot, label=60*\j:$\i$] at (60*\j:\R) {};
}
\end{tikzpicture}
\end{document}
编辑(1): 或者所有顶点之间都有互连:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1.5pt, outer sep=0pt},
every label/.style={inner sep=0pt}]
\newdimen\R
\R=1.3cm
\draw[red]
(300:\R) \foreach \x in {360,60} { -- (\x:\R) };
\foreach \i [count=\j] in { \overline{3},2,1,3,\overline{2},\overline{1} }
{
\node (n\j) [dot, label=60*\j:$\i$] at (60*\j:\R) {};
}
\foreach \i in {1,...,4}
{
\ifnum\i=1
\foreach \j in {2,...,5}
\draw (n\i) -- (n\j);
\else
\foreach \j in {\i,...,6}
\draw (n\i) -- (n\j);
\fi
}
\end{tikzpicture}
\end{document}
编辑(2): 编辑答案中添加的图像可以通过以下方式复制:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1.5pt, outer sep=0pt},
every label/.style={inner sep=0pt}]
\newdimen\R \R=1.3cm
\foreach \i [count=\j] in { \overline{3},2,1,3,\overline{2},\overline{1} }
{
\node (n\j) [dot, label=60*\j:$\i$] at (60*\j:\R) {};
\draw[red,semithick] (0,0) -- (n\j);
}
\scoped[on background layer]
{
\foreach \i in {1,2,...,6}
\foreach \j in {\i,...,6}
\draw (n\i) -- (n\j);
}
\end{tikzpicture}
\end{document}
答案2
x ? y :z
这是一个使用语法(含义if x then y else z
)和几个命令的TikZ 方式\foreach
。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\r{2}
\foreach \i in {1,...,6}
\path (\i*60:\r) coordinate (A\i);
\foreach \i in {1,...,6}
\foreach \j in {\i,...,6}
{
\pgfmathparse{\j-\i-3 ? "black" : "red"}
\draw[\pgfmathresult] (A\i)--(A\j);
}
\foreach \i/\itext in {1/{\overline 3},2/2,3/1,4/3,5/{\overline 2},6/{\overline 1}}
\fill (A\i) circle(2pt) ++(\i*60:.3) node{$\itext$};
\end{tikzpicture}
\end{document}
更新渐近线翻译
//http://asymptote.ualberta.ca/
unitsize(1cm);
real r=2;
pair[] A;
for (int i=0; i<6; ++i)
A[i]=r*dir(60*i);
for (int i=0; i<5; ++i)
for (int j=i+1; j<6; ++j)
if (j-i==3)
draw(A[i]--A[j],magenta);
else
draw(A[i]--A[j],blue);
string[] vlabel={"$\overline 1$","$\overline 3$","2","1","3","$\overline 2$"};
for (int i=0; i<6; ++i){
fill(circle(A[i],.1),purple);
label(vlabel[i],A[i]+.35*dir(60*i));
}
shipout(bbox(5mm,invisible));