我想使用 tikz 用灰色填充四条线(四边形)之间的空间。我该怎么做。
我还想将原点标记为“s”
\documentclass[12pt]{beamer}
\usepackage[T1]{fontenc}
\usetheme{metropolis}
\mode<handout>{
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatother
\begin{document}
\begin{frame}{Introduction}
\begin{block}{Pareto Optimal Solutions}
\begin{center}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\draw[thick,->] (0,0) -- (6,0);
\draw[thick,->] (0,0) -- (0,4.5);
\coordinate (Bone) at (1.7,2.8);
\coordinate (Btwo) at (3.2,1.2);
\coordinate (Bthree) at (4,2.8);
\draw [thick,-] (Origin) -- (Bone) (Bone) -- (Bthree) (Bthree) -- (Btwo) (Btwo) -- (Origin) node {};
\end{tikzpicture}
\end{center}
\end{block}
\end{frame}
\end{document}
答案1
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate[label={[below]$s$}] (Origin) at (0,0);
\coordinate (Bone) at (1.7,2.8);
\coordinate (Btwo) at (3.2,1.2);
\coordinate (Bthree) at (4,2.8);
\draw[thick,->] (0,0) -- (6,0);
\draw[thick,->] (0,0) -- (0,4.5);
\draw [thick,-,fill=gray] (Origin) -- (Bone) -- (Bthree) -- (Btwo) -- cycle;
\end{tikzpicture}
\end{document}
编辑:添加标签年代在中间,你可以猜测坐标,例如使用类似
\node at (2.5,2) {$S$};
或者你可以计算位置:
\usepackage{tikz}
\usetikzlibrary{calc}
...
\node at ($0.25*(Origin)+0.25*(Bone)+0.25*(Btwo)+0.25*(Bthree)$) {$S$};