如何在 TikZ 中翻转花括号的方向?

如何在 TikZ 中翻转花括号的方向?

我正在使用 TikZ 和以下代码绘制图片。如何将旁边的花括号转到$P_2$右边?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}[scale=1]
\draw[thick] (-1,0) rectangle +(6,7.5);
\filldraw[thick, top color=white,bottom color=red!50!] (0.5,0) rectangle node{$N_S$} +(1.3,0.5);
\filldraw[thick, top color=white,bottom color=red!50!] (2.2,0) rectangle node{$N_L$} +(1.3,0.65);
\filldraw[top color=white,bottom color=blue!50!] (0.5,0.5) rectangle node{$P_{1}$} +(1.3,0.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,0.65) rectangle node{$P_{2}$} +(1.3,1.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,1.0) rectangle node{$P_{3}$} +(1.3,1.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,1.65) rectangle node{$P_{4}$} +(1.3,2.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,2.5) rectangle node{$P_{5}$} +(1.3,2.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,3.65) rectangle node{$P_{6}$} +(1.3,3.0);
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (0.5,5.0) node [black,midway,xshift=-0.6cm] 
{\footnotesize $P_1$};
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt]
(3.5,0.65) -- (3.5,6.5)node [black,midway,xshift=9pt] {\footnotesize
$P_2$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

有一个mirror装饰选项,实际上可以改变路径的方向:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[scale=1]
\draw[thick] (-1,0) rectangle +(6,7.5);
\filldraw[thick, top color=white,bottom color=red!50!] (0.5,0) rectangle node{$N_S$} +(1.3,0.5);
\filldraw[thick, top color=white,bottom color=red!50!] (2.2,0) rectangle node{$N_L$} +(1.3,0.65);
\filldraw[top color=white,bottom color=blue!50!] (0.5,0.5) rectangle node{$P_{1}$} +(1.3,0.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,0.65) rectangle node{$P_{2}$} +(1.3,1.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,1.0) rectangle node{$P_{3}$} +(1.3,1.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,1.65) rectangle node{$P_{4}$} +(1.3,2.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,2.5) rectangle node{$P_{5}$} +(1.3,2.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,3.65) rectangle node{$P_{6}$} +(1.3,3.0);
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (0.5,5.0) node [black,midway,xshift=-0.6cm] 
{\footnotesize $P_1$};
\draw [decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt]
(3.5,0.65) -- (3.5,6.5) node [black,midway,xshift=0.8cm] {\footnotesize
$P_2$};
\end{tikzpicture}
\end{document}

答案2

另一种可能性是简单地翻转括号的起点和终点:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}[scale=1]
\draw[thick] (-1,0) rectangle +(6,7.5);
\filldraw[thick, top color=white,bottom color=red!50!] (0.5,0) rectangle node{$N_S$} +(1.3,0.5);
\filldraw[thick, top color=white,bottom color=red!50!] (2.2,0) rectangle node{$N_L$} +(1.3,0.65);
\filldraw[top color=white,bottom color=blue!50!] (0.5,0.5) rectangle node{$P_{1}$} +(1.3,0.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,0.65) rectangle node{$P_{2}$} +(1.3,1.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,1.0) rectangle node{$P_{3}$} +(1.3,1.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,1.65) rectangle node{$P_{4}$} +(1.3,2.0);
\filldraw[top color=white,bottom color=blue!50!] (0.5,2.5) rectangle node{$P_{5}$} +(1.3,2.5);
\filldraw[top color=white,bottom color=blue!50!] (2.2,3.65) rectangle node{$P_{6}$} +(1.3,3.0);
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt] (0.5,0.5) -- (0.5,5.0) node [black,midway,xshift=-0.6cm] {\footnotesize $P_1$};
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt] (3.5,6.5) -- (3.5,0.65) node [black,midway,xshift=9pt] {\footnotesize $P_2$};
\end{tikzpicture}
\end{document}

相关内容