让 LaTeX 计算分数的值

让 LaTeX 计算分数的值

我正在制作一个图,我想在x- 轴的位置出现一个勾号c/(1 + c),其中c是一个常数,我希望能够改变它。我不知道该怎么做。我试过使用\usetikzlibrary{calc},但到目前为止还没有成功。

平均能量损失

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\newcommand{\constant}{0.4}

\begin{document}%
\begin{tikzpicture}%
\begin{axis}[%
             xmin = 0,
             xmax = 1,
             xtick = {0,\constant}, % replace 0 by \constant/(1 + \constant)
             ymin = 0,
             ymax = 1
            ]%

\addplot[domain = 0:1] {\constant/(\constant + x)};

\end{axis}%
\end{tikzpicture}%
\end{document}%

答案1

例如:

\documentclass[tikz, border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\newcommand{\constant}{0.4}
\usepackage{xintexpr}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
             xmin = 0,
             xmax = 1,
             xtick =
             {\xinttheiexpr[2]\constant/(1+\constant)\relax,\constant}, % replace 0 by \constant/(1 + \constant)
% with 2 digits after decimal mark of precision which seems anyhow to be
% the format kept par tikz here
             ymin = 0,
             ymax = 1
            ]

\addplot[domain = 0:1] {\constant/(\constant + x)};

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容