答案1
使用 Ti 的解决方案钾Z 只是为了好玩:
\documentclass[tikz]{standalone}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[anchor=base] {$\overbrace{\texttt{jdbc}}$} node[above=2.5ex] {\textsf{\scriptsize Protocol}};
\node[anchor=base] (a) at (0.5,0) {\texttt{:}};
\node[anchor=base] (post) at (1.4,0) {$\overbrace{\texttt{postgres}}$};
\node[anchor=base] (name) at (1.4,1) {\textsf{\scriptsize Product/Vendor Name}};
\draw[->] (name)--(post);
\node[anchor=base] (b) at (2.3,0) {\texttt{:}};
\draw (4.3,0) node[anchor = base] {$\overbrace{\texttt{//localhost:5432/zoo}}$} node[above=2.5ex] {\textsf{\scriptsize Database Specific Connection Details}};
\node[rectangle, draw=none] (rect) at (0.5,-1) {\textsf{\scriptsize Colon Separators}};
\draw[->] (a)--(rect);
\draw[->] (b) to[in=0,out=-90] (rect);
\end{tikzpicture}
\end{document}
我说只是为了好玩因为这是不是最佳方式。如果文本不是
jdbc:postgres://localhost:5432/zoo
那么您必须改变(几乎)所有的坐标,例如at (1.4,0)
。
很抱歉没有提供最佳方法。由于我很少使用这种东西,所以我有点不熟悉。但是,上面提供的代码是基本的 Ti钾Z 确实不需要花费太多精力。所以我向你展示了该代码。
答案2
另一种可能性是使用tikzmark
do 将文本的不同元素设为不同的节点,并用 注释它们overlay
tikzpicture
。这样,如果文本发生变化,您就不必重新调整尺寸。(但是,您必须在行前后添加垂直空间,因为覆盖图片不会添加空间。)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark,decorations.pathreplacing}
\begin{document}
\texttt{\tikzmarknode{jdbc}{jdbc}\tikzmarknode{c1}{:}\tikzmarknode{postgres}{postgres}%
\tikzmarknode{c2}{:}\tikzmarknode{localhost}{//localhost:5432/zoo}}
\begin{tikzpicture}[overlay,remember picture,overbrace/.style args={#1 with #2}{%
thick,decorate,decoration={brace,raise=1pt},insert path={
(#1.north west) -- (#1.north east)
node[midway,above=2pt,font=\sffamily,align=center]{#2}}}]
\draw[overbrace=jdbc with Protocol];
\draw[overbrace=localhost with Database Specific\\ Connection Details];
\draw[thick,decorate,decoration={brace,raise=1pt}] (postgres.north west) --
(postgres.north east) coordinate[midway,above=2pt] (aux);
\draw[latex-] (aux) -- ++(0,12mm)
node[above,font=\sffamily,align=center]{Database Specific\\ Connection Details};
\draw[-latex] (c1) -- ++ (0,-1cm) node[below,font=\sffamily] (CS) {Colon separators};
\draw[-latex] (c2) to[out=-90,in=0] (CS);
\end{tikzpicture}
\end{document}