![绘制空心圆、半实圆和全实圆的正确方法是什么?](https://linux22.com/image/477791/%E7%BB%98%E5%88%B6%E7%A9%BA%E5%BF%83%E5%9C%86%E3%80%81%E5%8D%8A%E5%AE%9E%E5%9C%86%E5%92%8C%E5%85%A8%E5%AE%9E%E5%9C%86%E7%9A%84%E6%AD%A3%E7%A1%AE%E6%96%B9%E6%B3%95%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F.png)
我正在尝试使用 tikz 绘制简单的空心、半实心和全实心的圆圈。以下是我的代码:
\documentclass[12pt]{article}
\usepackage{tikz}
\newcommand*\emptycirc{\tikz\draw (0,0) circle (1.0ex);}
\newcommand*\halfcirc{\tikz\draw[fill] (0,0)-- (90:1ex) arc (90:270:1ex) -- cycle ;}
\newcommand*\fullcirc{\tikz\fill (0,0) circle (1.0ex);}
\begin{document}
\begin{tabular}{|c|}
\hline
\emptycirc\\ \hline
\halfcirc \\ \hline
\fullcirc \\ \hline
\end{tabular}
\end{document}
我想在半圆方面实现以下两个方面。我想
- 显示
halfcirc
圆圈的其余部分 - 我想控制半圆的半径,类似于圆(1.0ex)。
尝试了很多次,但都不起作用。
答案1
\documentclass[12pt]{article}
\usepackage{tikz}
\newcommand*\emptycirc[1][1ex]{\tikz\draw (0,0) circle (#1);}
\newcommand*\halfcirc[1][1ex]{%
\begin{tikzpicture}
\draw[fill] (0,0)-- (90:#1) arc (90:270:#1) -- cycle ;
\draw (0,0) circle (#1);
\end{tikzpicture}}
\newcommand*\fullcirc[1][1ex]{\tikz\fill (0,0) circle (#1);}
\begin{document}
\begin{tabular}{|c|}
\hline
\emptycirc \emptycirc[2ex]\\ \hline
\halfcirc \halfcirc[2ex]\\ \hline
\fullcirc \fullcirc[2ex]\\ \hline
\end{tabular}
\end{document}
如果需要更厚的边框,
\documentclass[12pt]{article}
\usepackage{tikz}
\newcommand*\emptycirc[1][1ex]{\tikz\draw[thick] (0,0) circle (#1);}
\newcommand*\halfcirc[1][1ex]{%
\begin{tikzpicture}
\draw[fill] (0,0)-- (90:#1) arc (90:270:#1) -- cycle ;
\draw[thick] (0,0) circle (#1);
\end{tikzpicture}}
\newcommand*\fullcirc[1][1ex]{\tikz\fill (0,0) circle (#1);}
\begin{document}
\begin{tabular}{|c|}
\hline
\emptycirc \emptycirc[2ex]\\ \hline
\halfcirc \halfcirc[2ex]\\ \hline
\fullcirc \fullcirc[2ex]\\ \hline
\end{tabular}
\end{document}
答案2
如果您想要圆形nodes
而不仅仅是圆形,您可以使用以下样式:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
fullcircle/.style={circle, draw=#1, fill=#1},
fullcircle/.default=black,
halfcircle/.style={circle, draw=#1,
path picture={\fill[#1] (path picture bounding box.north west) rectangle (path picture bounding box.south);}},
halfcircle/.default=black,
emptycircle/.style={circle, draw=#1, fill=none},
emptycircle/.default=black,
node distance=5mm
]
\node[fullcircle] (a) {}; \node[fullcircle=red, minimum size=5ex, right=of a] (b) {};
\node[halfcircle, below=of a] (a) {}; \node[halfcircle=red, minimum size=5ex, right=of a] (b) {};
\node[emptycircle, below=of a] (a) {}; \node[emptycircle=red, minimum size=5ex, right=of a] (b) {};
\end{tikzpicture}
\end{document}
答案3
使用xelatex
或运行lualatex
\documentclass[12pt]{article}
\usepackage{array}
\usepackage{unicode-math}
\setmathfont{XITS Math}
\begin{document}
\begin{tabular}{|>{$}c<{$}>{\Huge$}c<{$}|}\hline
\lgwhtcircle &\lgwhtcircle\\ \hline
\circlelefthalfblack &\circlelefthalfblack\\ \hline
\circlerighthalfblack &\circlerighthalfblack\\ \hline
\circlebottomhalfblack &\circlebottomhalfblack\\ \hline
\circletophalfblack &\circletophalfblack\\ \hline
\mdlgblkcircle &\mdlgblkcircle\\ \hline
\end{tabular}
\end{document}