![tikz でノードを囲む丸/長方形の括弧を描画する](https://rvso.com/image/298819/tikz%20%E3%81%A7%E3%83%8E%E3%83%BC%E3%83%89%E3%82%92%E5%9B%B2%E3%82%80%E4%B8%B8%2F%E9%95%B7%E6%96%B9%E5%BD%A2%E3%81%AE%E6%8B%AC%E5%BC%A7%E3%82%92%E6%8F%8F%E7%94%BB%E3%81%99%E3%82%8B.png)
次のコードで中括弧を描く方法を知っています。
\draw[decorate,decoration={brace,amplitude=5},-] (0.8,-0.75) -- (0.8,0.75);
しかし、今度は丸括弧、または長方形の括弧を描きたいです。どうすればこれができるのか誰か教えてもらえますか? 「brace」を他の値に変更することでこれを実現できますか?
結果は次のようになります: (いくつかの写真)
ただし、{いくつかの写真}
答え1
以下にスタイルを定義します
square left brace
、square right brace
、round left paren
、 そしてround right paren
その結果、次のようになります。
ノート:
- これは単純に
ncbar
、PSTricks \ncbar コマンドに相当する TikZ はありますか?。
コード:
\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
。
以下の推奨事項が賢明かどうかは、使用例によって異なりますが、あなたが望むような結果を達成できる可能性のある方法の1つは、\vphantom
騙すそして、(
そして[
が区切り文字。
ここでは、TikZ ライブラリを使用して、メインを基準として配置される独自の に\left(
と を配置します。\right)
node
node
positioning
\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}