在 tikz 中繪製包含節點的圓形/矩形括號

在 tikz 中繪製包含節點的圓形/矩形括號

我知道如何用以下程式碼繪製大括號:

\draw[decorate,decoration={brace,amplitude=5},-] (0.8,-0.75) -- (0.8,0.75);

但現在我想畫一個圓括號,或是一個矩形括號。誰能告訴我該怎麼做?是否可以透過將“大括號”更改為其他值來做到這一點?

結果應該是這樣的:(一些圖片)

但不是{一些圖片}

答案1

下面我定義樣式

  • square left brace,
  • square right brace,
  • round left paren, 和
  • round right paren

其產量:

在此輸入影像描述

筆記:

代碼:

\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

%% https://tex.stackexchange.com/questions/55068/is-there-a-tikz-equivalent-to-the-pstricks-ncbar-command
\tikzset{
    ncbar angle/.initial=90,
    ncbar/.style={
        to path=(\tikztostart)
        -- ($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
        -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
        -- (\tikztotarget)
    },
    ncbar/.default=0.5cm,
}

\tikzset{square left brace/.style={ncbar=0.5cm}}
\tikzset{square right brace/.style={ncbar=-0.5cm}}

\tikzset{round left paren/.style={ncbar=0.5cm,out=120,in=-120}}
\tikzset{round right paren/.style={ncbar=0.5cm,out=60,in=-60}}

\begin{document}

\begin{tikzpicture}
    \draw [red, thick] (0,0) to [square left brace ] (0,4);
    \draw [red, thick] (1,0) to [square right brace] (1,4);
    
    
    \draw [blue, thick] (3,0) to [round left paren ] (3,4);
    \draw [blue, thick] (4,0) to [round right paren] (4,4);
\end{tikzpicture}
\end{document}

答案2

brace不幸的是,TikZ 庫中沒有定義等效的圓括號和方括號decorations.pathreplacing

以下建議是否合理取決於您的用例,但實現您想要的目標的一種可能方法是利用\vphantom詭計事實是([分隔符

在這裡,我將\left(\right)放在自己的s 中,這些 s 相對於使用 TikZ 庫的nodemain 放置。nodepositioning

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\usepackage{graphicx}
\usepackage{mwe}

\begin{document}

\begin{tikzpicture}
    \node (picture) at (0,0) {\includegraphics[width=.5\textwidth]{image-a}};
    \node (left-paren) [left = of picture] {$\left(\vphantom{\includegraphics[width=.25\textwidth]{image-a}}\right.$};
    \node (right-paren) [right = of picture] {$\left.\vphantom{\includegraphics[width=.25\textwidth]{image-a}}\right)$};
\end{tikzpicture}

\end{document}

在此輸入影像描述

相關內容