I actually searched the whole forum for an example but I cant figure out how to create such a graphic..
Is there even a way to create such things?
I actually searched the whole forum for an example but I cant figure out how to create such a graphic..
Is there even a way to create such things?
There are probably several ways of doing it, but searching for such things can be tricky, in part because many questions are just like yours: an image, and the question "how do I do this?" And of course, there could well be that no one has asked how to make exactly such a diagram.
That said: Quick ugly hack before I turn in for the night. The numbers in the for-loop (0.12, 0.63 etc) correspond to the fractional horizontal distance between the lower left and lower right corner of the node with the URL, some fine tuning of those might be needed.
\documentclass[border=5mm]{standalone}
\usepackage{url}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node [inner xsep=0pt,name=foo] {\url{https://username:password@server.com:5000/api/person?id=1234#email}};
\foreach [remember=\xb as \xa (initially 0)] \xb/\txt in {
0.12/Schema,
0.63/Authority,
0.79/Path,
0.91/Query,
1/Fragment}
{
\draw ($(foo.south west)!\xa!(foo.south east)$) |- coordinate [pos=0.75] (m)
($(foo.south west)!\xb!(foo.south east) + (-1pt,-5pt)$) --
($(foo.south west)!\xb!(foo.south east) + (-1pt,0)$);
\draw (m) -- ++(0,-5pt) node[below, font=\scriptsize\sffamily] {\txt};
}
\end{tikzpicture}
\end{document}
Here is an alternative to Torbjørn's nice answer which is based on Torbjørn's very useful command \tikznode. The advantage is that it you can control the positions of the vertical bars more easily because they are determined by the nodes, but the downside is that it does not (yet?) work with \url. (EDIT: shortened the code, following the suggestion by (guess who ;-) Torbjørn T. The shorter legs at the beginning and end are on purpose, however, if you don't like them, replace \strut by \vphantom{x}, say.)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\tikznode}[2]{\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};}
\begin{document}
\texttt{\tikznode{0}{\strut}https:/\tikznode{1}{/}username:password\@server.com:5000\tikznode{2}{/}api/person\tikznode{3}{?}id=1234\tikznode{4}{\#}email\tikznode{5}{\strut}}
\begin{tikzpicture}[overlay,remember picture,font=\sffamily]
\coordinate[below=4pt of 0.south] (B);
\foreach [count=\X from 0, count=\Z] \Y in {Schema,Authority,Path,Query,Fragment}
{\draw ([xshift=-1pt]\Z.south) -- ([xshift=-1pt]\Z.south |-B) -| ([xshift=1pt]\X.south)
coordinate[pos=0.25](M-\X);
\draw (M-\X) -- ++(0,-3pt) node[below]{\Y};}
\end{tikzpicture}
\end{document}
\foreach [count=\X from 0, count=\Z] \Y in {Schema,Authority,Path,Query,Fragment}. Just noticed by the way that the first and last "leg" of the brackets are a bit shorter, because of the depth of the \strut.
– Torbjørn T.
Jul 21 '18 at 09:11
Here's a way using the text effects along path decoration to typeset the url as individual nodes which can then be used to position the braces.
\documentclass[tikz,border=2]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing,decorations.text}
\begin{document}
\begin{tikzpicture}
\path [decoration={
text effects along path,
text={https://username:password@server.com:5000/api/person?id=1234\#email},
text effects/.cd,
text along path,
path from text,
character count=\n,
every character/.style={
font=\tt, name=n\n,
text height=0.666em, text depth=0.125em,
minimum height=0}},
decorate] (0,0);
\foreach \i/\j/\name in {
1/8/Schema,9/41/Authority,42/52/Path,53/60/Query,61/66/Fragment}
\draw [decoration={brace, mirror, amplitude=6}, decorate]
($(n\i.south west)+(0.05,0)$) -- ($(n\j.south east)-(0.05,0)$)
node [midway, below=8, font=\scriptsize\sffamily] {\name};
\end{tikzpicture}
\end{document}