在tikz中填充线和圆弧之间的表面

在tikz中填充线和圆弧之间的表面

我有下图:

在此处输入图片描述

我想要表面 A 填充颜色。这是我的代码:

\documentclass[12pt]{article}
\usepackage{tikz, pgfplots}
\usepackage[utf8]{inputenc}
\usetikzlibrary{positioning,calc,arrows,patterns}
\usepackage{xcolor}
\usepackage{tkz-euclide}
\pgfdeclarelayer{pre main}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}

\begin{document}
\begin{center}
\begin{tikzpicture}
\draw (1,-3) arc (180:360:4cm and 2cm);
\draw[name path=tra] (0.5,-4) -- (9,-4);
\draw node at (4,-4.5) {$A$};
\end{tikzpicture}
\end{center}

\end{document}

答案1

\clip

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{scope}
    \clip (0.5,-4) rectangle (9,-6);
    \path[fill=green!20] (1,-3) arc (180:360:4cm and 2cm);
\end{scope}
\draw (1,-3) arc (180:360:4cm and 2cm);
\draw (0.5,-4) -- (9,-4);
\draw node at (4,-4.5) {$A$};
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

这个答案基于什么哈拉尔·利希滕斯坦建议,始终应给予信用。我已将标签完美地插入水平线的中心。

输出

\documentclass[12pt]{article}
\usepackage{tikz, pgfplots}
\usepackage[utf8]{inputenc}
\pgfplotsset{compat=1.18}
\usetikzlibrary{fillbetween, patterns, intersections}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[name path=A] (1,-3) arc (180:360:4cm and 2cm);
\draw[name path=B] (0.5,-4) -- (9,-4);
\tikzfillbetween[of=A and B,split,every even segment/.style={white!1}]{pattern=crosshatch, pattern color=red};
\tikzfillbetween[of=A and B,split,every even segment/.style={white!1}]{red,opacity=0.2};%solid colour
\draw[] (0.5,-4) -- node[below=0.25cm,fill=white]{X} (9,-4);%same as path B but with the label inserted in the middle
\end{tikzpicture}
\end{center}
\end{document}

相关内容