TikZ 橡皮擦工具

TikZ 橡皮擦工具

我想要一种风格(或类似的东西),我们称之为ERASE。假想工具可以作为一种方便的逆剪辑或者橡皮在范围内。具体方法在下面的 MWE 中的评论中询问。MWE 是我的用例的抽象形式(如果你不喜欢背景,可以考虑色轮图从复杂的分析到抚平你烦躁的情绪)。

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{shadings,calc}
\tikzset{nodeStyle/.style={draw,rounded corners,thick,font=\bfseries{}}}
\tikzset{ERASE/.style={}}% just a placeholder

\begin{document}
\begin{tikzpicture}
    \shade[shading=color wheel white center] (0,0) rectangle (10,10);

    \draw[thick] (0,0) -- (10,5);
    \node[nodeStyle,fill=white] at (5,2.5) {filled};
    %This is readable but removes the background. 

    \draw[thick] (0,2) -- (10,7);
    \node[nodeStyle] at (5,4.5) {not filled};

    \begin{scope}
        \draw[line width=1.5ex,color=red!50] (0,6.05) -- (10,6.95);%by @marmot
        \draw[thick] (0,4) -- (10,9);
        \node[nodeStyle,ERASE] at (5,6.5) {ERASE to be implemented};
            % erases everything in this scope "behind" this new object 
            % such that the diagonal line in this node is not visible and 
            % the text is easy to read and the coding is convenient 
    \end{scope}

    \begin{scope}
        % This just illustrates that clip can be used inside a scope
        % thus the desired EREASE instruction might be possible. 
        \clip (1,7) rectangle (8,10);
        \draw[thick] (0,6) -- (8,10);
    \end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

此假想工具可能不适合涉及多条路径的更复杂用例。欢迎提出任何改进用例的建议。

答案1

这是一个使用反向剪辑技巧。我不确定是否可以轻松地将其实现为强壮的样式可以添加到节点,因为clip不允许额外的选项。但是,除此之外,我认为这可以做到。编辑:通过使用 简化了事项use path

\documentclass{memoir}
\usepackage{fontspec,amsmath,tikz}
\usetikzlibrary{shadings,calc,backgrounds}
\tikzset{nodeStyle/.style={draw,rounded corners,thick}}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzset{ERASE/.style={save path=\tmprotect
% append after command={\pgfextra{\clip[overlay]
% (\tikzlastnode.south east) rectangle (\tikzlastnode.north west)
% [reverseclip];
% }}
        }}% just a placeholder
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}

\begin{document}
\begin{tikzpicture}
    \shade[shading=color wheel white center] (0,0) rectangle (10,10);

    \draw[thick] (0,0) -- (10,5);
    \node[nodeStyle,fill=white,font=\bfseries] at (5,2.5) {filled};
    %This is readable but removes the background. 

    \draw[thick] (0,2) -- (10,7);
    \node[nodeStyle,font=\bfseries] at (5,4.5) {not filled};

    \begin{scope}
        \node[nodeStyle,ERASE,font=\bfseries] at (5,6.5) (erase) {ERASE has been implemented};
            % erases everything in this scope "behind" this new object 
            % such that the diagonal line in this node is not visible and 
            % the text is easy to read and the coding is convenient 
        \clip[use path=\tmprotect,reverseclip]; 
        \draw[thick] (0,4) -- (10,9);   
        \draw [ultra thick,red] (0,6.05) -- (10,6.95);
    \end{scope}

    \begin{scope}
        % This just illustrates that clip can be used inside ascope
        % thus the desired EREASE instruction might be possible. 
        \clip (1,7) rectangle (8,10);
        \draw[thick] (0,6) -- (8,10);
    \end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

现在圆角也受到尊重。

在此处输入图片描述

相关内容