![如何绘制一半一半彩色的圆圈?](https://linux22.com/image/354488/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E4%B8%80%E5%8D%8A%E4%B8%80%E5%8D%8A%E5%BD%A9%E8%89%B2%E7%9A%84%E5%9C%86%E5%9C%88%EF%BC%9F.png)
我用了这个答案在表格中创建实心圆。我正在创建一个使用交通灯系统来监控进度的表格。虽然我能够制作实心圆,但是否可以制作半圆和半圆。目标是同时拥有红色、橙色和绿色的圆圈以及红色/橙色和橙色/绿色的半圆和半圆的组合,以提供更细微的进度视图。
平均能量损失
\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{lipsum} % just for dummy text
\begin{document}
\begin{table}[H]
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
\hline
\textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \tikz\draw[green,fill=green] (0,0) circle (1.0ex); & What is end product \\ \hline
Aim 2 & what needs to be done & who & when & \tikz\draw[orange,fill=orange] (0,0) circle (1.0ex); & What is end product \\ \hline
Aim 3 & what needs to be done & who & when & \tikz\draw[red,fill=red] (0,0) circle (1.0ex); & What is end product \\ \hline
\end{tabularx}
\end{table}
\end{document}
答案1
像这样吗?
\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{tikz,float}
\usepackage{tabularx}
\usepackage{xparse}
\NewDocumentCommand{\statcirc}{ O{#2} m }{%
\begin{tikzpicture}
\fill[#2] (0,0) circle (1.0ex); % Fill circle with base colour (arg#2)
\fill[#1] (0,0) -- (180:1ex) arc (180:0:1ex) -- cycle; % Fill a half circle filled with second colour (arg#1), if specified
\end{tikzpicture}
}
\begin{document}
\begin{table}[H]
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
\hline
\textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \statcirc{green} & What is end product \\ \hline
Aim 2 & what needs to be done & who & when & \statcirc[orange]{green} & What is end product \\ \hline
Aim 3 & what needs to be done & who & when & \statcirc[red]{orange} & What is end product \\ \hline
\end{tabularx}
\end{table}
\end{document}
如果您想要半圆,请提供第二种颜色作为可选参数。第二种颜色将显示在顶部。
\statcircle[top colour]{bottom colour}
关于 TikZ 代码的一点说明:
\fill[#1] (0,0) -- (180:1ex) arc (180:0:1ex) -- cycle;
\fill[#1]
:创建具有指定颜色的填充形状(0,0) -- (180:1ex)
:从 (0,0) 到极坐标中指定的点、180 度(从正 x 轴顺时针测量)和半径 1ex“绘制”形状路径。arc (180:0:1ex)
:继续将形状路径绘制为圆弧,固定半径 1ex,起始角度 180 度,终止角度 0 度。这将创建半圆。-- cycle;
:完成循环回到原点
考虑到这一点,如果您想要垂直分割圆,您只需要在绘制圆弧时更改起始和终止角度。例如:
\fill[#1] (0,0) -- (90:1ex) arc (90:270:1ex) -- cycle;
给你:
\fill[#1] (0,0) -- (45:1ex) arc (45:215:1ex) -- cycle;
给你:
答案2
再举一个使用shapes.geometry
包的简单例子:-)
\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\newcommand{\semaphore}[2]{
\tikz[node distance=3mm,baseline]
{
\node (s1) [semicircle, fill=#1, minimum size=3mm] {};
\node (s1) [semicircle, fill=#2, minimum size=3mm, rotate=180, below=of s1] {};
}
}
\usepackage{tabularx}
\usepackage{ragged2e} % added for better adjust of cells' content
\newcolumntype{L}{>{\RaggedRight}X} % for cells with left aligned content
\usepackage{lipsum} % just for dummy text
\begin{document}
\begin{table}
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
\hline
\textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \semaphore{green}{green} & What is end product \\ \hline
Aim 2 & what needs to be done & who & when & \semaphore{orange}{green} & What is end product \\ \hline
Aim 3 & what needs to be done & who & when & \semaphore{red}{orange} & What is end product \\ \hline
\end{tabularx}
\end{table}
\end{document}
附录: 对于半圆旋转任意角度:
\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\newcommand{\semaphore}[3]{% #1: color of circle,
% #2: color of semicircle
% #3: angle of semicircle
\tikz[node distance=0mm,baseline]
{
\node (s1) [circle, fill=#1, minimum size=6mm] {};
\node [semicircle, fill=#2,
inner sep=0pt, outer sep=0pt, minimum size=3mm,
anchor=south,
at={(s1.center)}, rotate=#3] {};
}
}% end of command
\usepackage{makecell, tabularx}
\usepackage{ragged2e} % added for better adjust of cells' content
\newcolumntype{L}{>{\RaggedRight}X} % for cells with left aligned content
\usepackage{lipsum} % just for dummy text
\usepackage{graphicx}
\begin{document}
\begin{table}
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{| L | L | l | l | c | L |}
\hline
\textbf{Strategy} & \textbf{Action} & \textbf{Owner} & \textbf{Due} & \textbf{Status} & \textbf{Outcome} \\ \hline
Aim 1 & what needs to be done & who & when & \semaphore{green}{green}{0} & What is end product \\ \hline
Aim 2 & what needs to be done & who & when & \semaphore{orange}{green}{90} & What is end product \\ \hline
Aim 3 & what needs to be done & who & when & \semaphore{red}{orange}{45} & What is end product \\ \hline
Aim 4 & what needs to be done & who & when & \semaphore{green}{red}{0} & What is end product \\ \hline
Aim 5 & what needs to be done & who & when & \semaphore{green}{red}{30} & What is end product \\ \hline
\end{tabularx}
\end{table}
\end{document}
答案3
在工作中,我们也使用四分之一信号灯。
使用包裹很容易就能完成tkz-euclide
。
我创建了一个pic
包含三个参数的args
窗口:背景颜色、扇区角度的等级(90/180/270),扇区必须以另一种方式着色,另一种颜色。如果角度 = 0(即只有一种颜色),则第三个参数将被忽略。
\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{tkz-euclide}
\tikzset{%
pics/sema/.style args={#1/#2/#3}{code={%
\ifstrequal{#2}{0}{%
\node[circle,minimum width=2mm,draw,fill=#1] {};
}{%
\tkzDefPoint(0,0){O}
\tkzDrawSector[R,fill=#1](O,2mm)(90,90-#2)
\tkzDrawSector[R,fill=#3](O,2mm)(90-#2,90-360)
}
}},
}
\usepackage{float}
\usepackage{tabularx}
\usepackage{lipsum} % just for dummy text
\begin{document}
\begin{table}[H]
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
\hline
\textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \tikz\pic{sema=yellow/0/}; & What is end product \\ \hline
Aim 2 & what needs to be done & who & when & \tikz\pic{sema=yellow/90/green}; & What is end product \\ \hline
Aim 3 & what needs to be done & who & when & \tikz\pic{sema=yellow/180/green}; & What is end product \\ \hline
Aim 4 & what needs to be done & who & when & \tikz\pic{sema=yellow/270/green}; & What is end product \\ \hline
Aim 5 & what needs to be done & who & when & \tikz\pic{sema=red/0/}; & What is end product \\ \hline
Aim 6 & what needs to be done & who & when & \tikz\pic{sema=red/90/yellow}; & What is end product \\ \hline
Aim 7 & what needs to be done & who & when & \tikz\pic{sema=red/180/yellow}; & What is end product \\ \hline
\end{tabularx}
\end{table}
\end{document}
tkz-euclide
PS = 如果你有3.02 之前的旧版本,请添加\usetkzobj{all}
在加载包后添加。对于最新版本,请不要使用它,请参阅:LaTeX 找不到文件“tkz-obj-angles.tex”
答案4
像这样吗?
我擅自添加了 booktabs 包并删除了表格线(一般不建议这样做,请参阅 booktabs 包)。当然,如果您确实需要它们,您可以将它们添加回来;这最终主要取决于个人喜好。
如果您想仔细阅读 booktabs 文档,可以在这里找到:http://ctan.org/pkg/booktabs
为了方便起见,我创建了一些用于创建圆圈的新命令。当然,您也可以创建一个命令并将所需的颜色作为参数传递给它。您的里程和偏好可能会有所不同。
\documentclass[12pt,a4paper]{memoir}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{tabularx}
\newcommand*\greencirc{\tikz\fill[fill=green] (0,0) circle (1.0ex);}
\newcommand*\orangecirc{\tikz\fill[fill=orange] (0,0) circle (1.0ex);}
\newcommand*\redcirc{\tikz\fill[fill=red] (0,0) circle (1.0ex);}
\newcommand*\redorangecirc{%
\begin{tikzpicture}
\fill[red] (0,0) circle (1ex);
\clip (-1ex,-1ex) rectangle (1ex,0);
\fill[orange] (0,0) circle (1ex);
\end{tikzpicture}}
\newcommand*\orangegreencirc{%
\begin{tikzpicture}
\fill[orange] (0,0) circle (1ex);
\clip (-1ex,-1ex) rectangle (1ex,0);
\fill[green] (0,0) circle (1ex);
\end{tikzpicture}}
\begin{document}
\begin{table}
\setlength\extrarowheight{2mm}
\centering
\begin{tabularx}{\textwidth}{XXllcX}
\toprule
\textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\
\midrule
Aim 1 & what needs to be done & who & when & \greencirc & What is end product \\
Aim 2 & what needs to be done & who & when & \orangecirc & What is end product \\
Aim 3 & what needs to be done & who & when & \redcirc & What is end product \\
Aim 4 & what needs to be done & who & when & \redorangecirc & What is end product \\
Aim 5 & what needs to be done & who & when & \orangegreencirc & What is end product \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
附注:无需加载包xcolor
;tikz
它会自行加载。