使用 tikz 绘制 \rhd 使其变大

使用 tikz 绘制 \rhd 使其变大

我想\rhd用 Tikz 绘图。为此,我获取高度和宽度\rhd,然后将它们用作 Tikz 中的 x 和 y。我期望这能让 Tikz 准确绘图,\rhd但它绘制了一个更大的版本,我不明白为什么。

\documentclass{article}
\usepackage{amssymb}
\usepackage{calc}
\usepackage{tikz}
\begin{document}
    \newlength{\testwidth}
    \newlength{\testheight}
    \newsavebox{\testbox}
    \savebox{\testbox}{$\mathsurround=0pt\rhd$}%
    \settowidth{\testwidth}{\usebox{\testbox}}%
    \settototalheight{\testheight}{\usebox{\testbox}}%
    \pgfmathsetlength{\testheight}{\testheight / 2}%
    \begin{tikzpicture}[x=\the\testwidth, y=\the\testheight]
    \draw (0,1) -- (1, 0) -- (0, -1) -- (0, 1);
    \end{tikzpicture}
    $\rhd$
\end{document}

答案1

与大多数字符一样,这​​个字符两侧都有一些空白。设置\mathsurround不会删除它。顺便说一句,TicalcZ 具有内置包的功能,您可以使用widthheight代替执行所有框操作。(还有一个小的概念错误,您还需要减去线宽,但大部分差异来自空白。)

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}
\begin{document}  
    \begin{tikzpicture}[x={width("$\mathsurround=0pt\rhd$")-\pgflinewidth}, y={height("$\mathsurround=0pt\rhd$")-\pgflinewidth}]
    \draw (0,0.5) -- (1, 0) -- (0, -0.5) -- cycle;
    \path (-\pgflinewidth/2,-1.2) 
    node[draw,inner sep=0pt,outer sep=0pt,right=0pt]{$\mathsurround=0pt\rhd$};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这是一份文档,其中绘制的符号与\rhdTikz 非常相似(但不完全相似,如果您放大到一定程度就会看到)。

\documentclass{article}
\usepackage{amssymb}
\usepackage{calc}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{transparent}
\usepackage{xfp}
\begin{document}
    \pdfpkresolution=2000

    \def\xrbls{-0.452} % Ratio of baseline
    \def\xrealwidthratio{0.73} % Relative width (i.e. total width divided by width without spaces)
    \def\xrealheightratio{0.98}
    \def\xleftspaceratio{0.11} % Ratio of white spaces on the left
    \def\xbotspaceratio{-0.005}
    \def\tipshift{-0.02}

    \def\xrightspaceratio{\fpeval{1 - \xrealwidthratio - \xleftspaceratio}}
    \def\xtopspaceratio{\fpeval{1 - \xrealheightratio - \xbotspaceratio}}

    \newlength{\xwidth} % Total width
    \newlength{\xheight}
    \newlength{\xdepth}
    \newlength{\xtotalheight}

    \newbox\rhdbox%
    \savebox{\rhdbox}{$\mathsurround=0pt\rhd$}%
    \setlength{\xwidth}{\wd\rhdbox}
    \setlength{\xheight}{\ht\rhdbox}
    \setlength{\xdepth}{\dp\rhdbox}
    \setlength{\xtotalheight}{\xheight + \xdepth}

    \newcommand{\tikzrhd}{
        \mathrel{\begin{tikzpicture}[line join=round, baseline=(baseline)]% TODO
            \coordinate (baseline) at (0, \dimexpr -\xtotalheight / 2 + \xdepth \relax);
            \coordinate (topleft) at (0, \dimexpr \xtotalheight / 2 \relax);
            \coordinate (botright) at (\xwidth, \dimexpr -\xtotalheight / 2 \relax);
            \useasboundingbox (topleft) rectangle (botright);
            %\draw[yellow, line width=0pt] (topleft) rectangle (botright);
            \coordinate (headtop) at (\dimexpr \xleftspaceratio \xwidth + \pgflinewidth / 2 \relax, \dimexpr \fpeval{0.5 - \xtopspaceratio} \xtotalheight - \pgflinewidth / 2 \relax);
            \coordinate (headbot) at (\dimexpr \xleftspaceratio \xwidth + \pgflinewidth / 2 \relax, \dimexpr \fpeval{-0.5 + \xbotspaceratio} \xtotalheight + \pgflinewidth / 2 \relax);
            \coordinate (headright) at (\dimexpr \fpeval{1 - \xrightspaceratio} \xwidth + \pgflinewidth / 2 \relax, 0);
            \draw[blue] (headtop) -- (headright) -- (headbot) -- (headtop) -- (headright); % , dash pattern=on 0.2pt off 0.2pt
            \end{tikzpicture}}
    }




    \newcommand{\testrhd}{
        \mathrel{\rhd}
    }

    Sizes:\\%
    \newbox\mybox%
    \savebox{\mybox}{$\mathsurround=0pt\tikzrhd$}%
    \color{blue}\the\wd\mybox $\times$ (\the\ht\mybox + \the\dp\mybox)\\
    \savebox{\mybox}{$\mathsurround=0pt\testrhd$}%
    \color{red}\the\wd\mybox $\times$ (\the\ht\mybox + \the\dp\mybox)%

    % https://tex.stackexchange.com/questions/21644/how-do-you-superimpose-two-symbols-over-each-other
    \makeatletter
    \newcommand{\superimpose}[2]{%
        {\ooalign{$#1\@firstoftwo#2$\cr\hfil$#1\@secondoftwo#2$\hfil\cr}}}
    \makeatother

    \newcommand{\maketest}[1]{
        $\mathpalette\superimpose{{\color{blue}\transparent{0.5}#1{\tikzrhd}}{\color{red}\transparent{0.5}#1{\testrhd}}}$
    }

    \newcommand{\overunderline}[1]{
        \overline{\underline{#1}}
    }

    \newcommand{\expa}[1]{
        #1^a
    }

    \maketest\overunderline
    \maketest\expa
    \maketest\boxed
\end{document}

相关内容