5

I would like to obtain a tikz picture that looks like the following. Can you help me to complete my code to achieve that result?

enter image description here

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

   \begin{tikzpicture}[x=50]
       \draw (-0.2,0) -- (1.2,0);      
       \draw (0, 0) node[below=7pt] {$a_1$};
       \draw[] (0,-0.1) -- (0,0.1);
       \draw (1, 0) node[below=7pt] {$a_2$};       
       \draw[] (1,-0.1) -- (1,0.1);
   \end{tikzpicture}

\end{document}

EDIT

I like @Qrrbrbirlbel's proposal, but I would like to make the "[" and ")" symbols a little bit larger. Any idea?

3 Answers 3

7

You can adjust the size to what you prefer (update removes a superfluous line, left-over from initial code).

\documentclass[border=6pt,tikz]{standalone}
\usepackage[T1]{fontenc}    % better to have fontenc *before* inputenc
\usepackage[utf8]{inputenc}

\usepackage[english]{babel}


\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
       \draw (-0.2,0) -- (1.2,0); 
       \draw [thick] (0.1,-.25) -- (0,-.25) -- (0,.25) -- (0.1,.25);     
       \draw (0,-.25) node [anchor=north] {$a_1$};
       \draw (1,-.25) node [anchor=north] {$a_2$};       
       \draw [thick] (0.7,-.25) .. controls (1.05,-0.2) and (1.05,0.2)
                                .. (0.7,.25);
   \end{tikzpicture}
\end{document}

tikz exercise

5

I’d just use arrow tips here.

For bigger arrow tips, you need to increase the line width.

You can also use the decorations.markings library with the \arrow macro customized with a scaling (only yscale or xscale works, too) or other options to place “arrows” on the line.

It is also possible to just add textual content to the line, say a [ and a ) where you have control over font (sizes, series, etc.) and you can also scale the node if necessary.

The arrows.meta library from the CVS version of TikZ (see How to install a current version of TikZ?) allows us to do this very easily with arrows={[scale=2]} (or any option whatsoever). It is also possible to give options to the arrow tip directly, say

\draw [{Bracket[right,red]}-{Arc Barb[arc=270]}] …;

Code

\documentclass[tikz, border={0pt 0pt 0pt 6pt}]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\usetikzlibrary{arrows.meta}% CVS
\begin{document}
\begin{tikzpicture}[inner sep=+0pt]
  \draw (+0pt,+0pt) -- ++(right:+10pt) coordinate (@);
  \draw[[-)] (@) node[below=+6pt] {$a_1$} -- ++ (right:+50pt) node[below=+6pt] {$a_2$} coordinate (@);
  \draw (@) -- ++ (right:+10pt);
\end{tikzpicture}

\tikz[inner sep=+0pt, outer sep=+0pt, nodes={below=+6pt}]
  \draw[decoration={
    markings, mark=at position .2 with {\arrow[line width=.7\pgflinewidth,scale=2]{[}},
              mark=at position .8 with {\arrow[line width=.7\pgflinewidth,scale=2]{)}}},
        postaction=decorate]
    (+0pt,+0pt) -- node[pos=.2, below=+3pt] {$a_1$} node[pos=.8, below=+3pt] {$a_2$} ++(right:+70pt);


\tikz[label position=below, inner sep=+0pt, outer sep=+0pt, every label/.style={font=},
  label distance=+3pt, nodes={font=\bfseries}]
  \draw (+0pt,+0pt) -- node[pos=.2,label=$a_1$] {[} node[pos=.8,label=$a_2$] {)} ++(right:+70pt);

\begin{tikzpicture}[inner sep=+0pt, arrows={[scale=2]}]% CVS
  \draw (+0pt,+0pt) -- ++(right:+10pt) coordinate (@);
  \draw[Bracket-Arc Barb] (@) node[below=+6pt] {$a_1$} -- ++ (right:+50pt) node[below=+6pt] {$a_2$} coordinate (@);
  \draw (@) -- ++ (right:+10pt);
\end{tikzpicture}
\end{document}

Output

enter image description here enter image description here enter image description here enter image description here

2
  • Thank you! I like it very much. Is it easy to make the "[" and ")" symbols a little bit larger?
    – user7064
    Commented Nov 6, 2013 at 10:22
  • @user7064 Sorry, I somehow missed your comment. I have updated my answer with a few ideas. Apart from just drawing the symbols yourself as in another answer, there are a few options. Commented Nov 7, 2013 at 18:16
2

262 keystrokes (compared to the existing answer with 299 keystrokes) with PSTricks.

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(5,1)
    \pstGeonode[PointName={a_1,a_2},PosAngle=-90,PointSymbol=none](1.2,.6){A}(3.8,.6){B}
    \pcline[nodesep=-1](A)(B)
    \psline{[-)}(A)(B)
\end{pspicture}
\end{document}

enter image description here

As you want to get a bigger [ and ), I modified the above code as follows.

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(5,1)
    \pstGeonode[PointName={a_1,a_2},PosAngle=-90,PointSymbol=none,PointNameSep=13pt](1.2,.65){A}(3.8,.65){B}
    \pcline[nodesep=-1](A)(B)
    \psline[arrowscale=2]{[-)}(A)(B)
\end{pspicture}
\end{document}

enter image description here

0

You must log in to answer this question.

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