7

I need to explain the structure of a URL. I would like to do this with braces. To produce the following

http://www.example.com/page.html?foo=bar&bar=foo
--v---|-------v-------|----v----|-v-|-v-|-v-|-v-|
service     address      page    parameter

the ---v--- are to represent the braces. I tried to do this by guessing the coordinates where to start, but already fail when I need to graphically draw the brace. I didn't even get to position the braces accordingly.

Is there an easy way to achieve this, without punctional positioning of the brace?

1 Answer 1

13

This is a solution without using tikz, it is easy and fast. I added a \vphantom{p} in the last two braces in order to have the same vertical alignment.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\[
\underbrace{\texttt{http://}}_{\text{service}}
\underbrace{\texttt{www.example.com/}}_{\text{address}}
\underbrace{\texttt{page.html?}}_{\text{page}}
\underbrace{\texttt{\vphantom{p}foo=bar}}_{\text{par}}\texttt{\&}
\underbrace{\texttt{\vphantom{p}bar=foo}}_{\text{par}}
\]
\end{document}

enter image description here

If you have a lot of such descriptions you can also define a command to keep things more ordered:

\documentclass{article}
\usepackage{amsmath}

\newcommand\linkdesc[2][]{%
    \underbrace{\texttt{#2}}_{\text{#1}}
}

\begin{document}
\[
\linkdesc[service]{http://}
\linkdesc[address]{www.example.com/}
\linkdesc[page]{page.html?}
\linkdesc[par]{\vphantom{p}foo=bar}\texttt{\&}
\linkdesc[par]{\vphantom{p}bar=foo}
\]
\end{document}
3
  • 1
    You should probably write “service”, “address”, etc. as \text{service}, etc., or \text{\itshape service} if you want italics. Commented Oct 14, 2013 at 13:11
  • @HaraldHanche-Olsen yes you're right, in that case one needs to include the amsmath package
    – Red
    Commented Oct 14, 2013 at 13:15
  • 2
    Or without amsmath, replace \text{service} by \mbox{\scriptsize service} (which, indeed, is rather cumbersome to write). Btw. shouldn't the 'page' brace end with the 'l' and not with the question mark?
    – Alex
    Commented Oct 14, 2013 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .