enter image description here

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?

  • Do you need it as an image? And what about the font? Could it be the standard for the? In math mode something similar could be obtained quite easyly. Let me know – phollox Jul 20 '18 at 22:59

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.

enter image description here

\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 {
\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};


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.)

\newcommand{\tikznode}[2]{\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};}
\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)
 \draw (M-\X) -- ++(0,-3pt) node[below]{\Y};}

enter image description here

  • 1
    Suggestion for minor (possible) improvement: \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 9:11
  • @TorbjørnT. Thanks! Done! (The shorter legs at the beginning and end were on purpose but I added a description of how to make them longer.) – user121799 Jul 21 '18 at 13:49

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.

\path [decoration={
    text effects along path,
    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 {
  \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};

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.