tikz 노드에 대한 사용자 정의 음영 패턴

tikz 노드에 대한 사용자 정의 음영 패턴

'일반적인' 방식과 다른 노드 음영을 달성하는 방법을 찾고 있습니다.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[top color=red, bottom color=green] {};
\end{tikzpicture}
\end{document}

이 예에서는 그라데이션이 있습니다. 즉, 중간 색상이 실제 상단 및 하단 색상과 다릅니다. 이를 변경할 수 있습니까? 즉, 다른 중간 색상 없이 색상(위쪽= 빨간색, 아래쪽=녹색)을 확실하게 분리하거나 그라데이션 속성을 변경할 수 있습니까?

답변1

이와 같이?

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,
    append after command={
        \pgfextra
            \fill[green] (\tikzlastnode.south west) rectangle (\tikzlastnode.east);
            \fill[red] (\tikzlastnode.north west) rectangle (\tikzlastnode.east);
    \endpgfextra
    }] {A};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

업데이트

또는 path picture옵션을 사용하면 훨씬 더 쉽습니다.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{tikzpicture}
\node[draw, fill=red,
        path picture={\fill[green] (path picture bounding box.west) rectangle (path picture bounding box.south east);}] {A};
\end{tikzpicture}

\end{document}

관련 정보