# Add vertical arrow on Quartil

I wanted to make picture looks like this.

What I have done so far,

\documenclass[a4paper]{article}
\begin{document}
$$\underbrace{2\quad 4\quad 6\quad 6}_{\textrm{empat nilai}} \quad \underset{Q_2}{7} \quad \underbrace{9\quad 9\quad 11\quad 12}_{\textrm{empat nilai}}$$
\end{document}


the output

I want to add vertical arrow pointing the number for Q1, Q2 or Q3. How can I do that?

You can do that with \substack.

Unrelated: don't use $$…$$ for displayed equation in LaTeX: – this is a plain TeX construct, and it can result in a bad vertical spacing. Use $…$ instead.

\documentclass[a4paper]{article}
\usepackage{amsmath}

\begin{document}

$\underbrace{2\quad 4\quad 6\quad 6}_{\textrm{empat nilai}} \quad \underset{\substack{\uparrow\\Q_2}}{7} \quad \underbrace{9\quad 9\quad 11\quad 12}_{\textrm{empat nilai}}$

\end{document}


I would just draw the whole thing with TikZ rather than messing around with arrows from some fonts.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,chains,decorations.pathreplacing,calligraphy}
\begin{document}
$\begin{tikzpicture}[decoration={calligraphic brace,mirror,raise=0.5ex}] \path[start chain=A going right,node distance=1em] foreach \x in {2,4,6,6,7,9,9,11,12}{node[on chain]{\x}}; \draw[decorate,thick] (A-1.south west) -- node[below=1ex] {empat nilai} (A-4.south east); \draw[decorate,thick] (A-6.south west) -- node[below=1ex] {empat nilai} (A-9.south east); \draw[latex-] (A-5.south) -- ++ (0,-1em) node[below]{Q_2}; \end{tikzpicture}$

$\begin{tikzpicture}[decoration={calligraphic brace,mirror,raise=0.5ex}] \path[start chain=A going right,node distance=1em] foreach \x in {2,4,6,6,7,9,9,11,12}{node[on chain]{\x}}; \foreach \x in {1,3,6,8} {\draw[decorate,thick] (A-\x.south west) -- (A-\the\numexpr\x+1\relax.south east); } \draw[latex-] ((A-2.south)!0.5!(A-3.south)) -- ++ (0,-1em) node[below]{Q_1}; \draw[latex-] (A-5.south) -- ++ (0,-1em) node[below]{Q_2}; \draw[latex-] ((A-7.south)!0.5!(A-8.south)) -- ++ (0,-1em) node[below]{Q_3}; \end{tikzpicture}$

\end{document}


With a friendly syntax (but unfriendly code, but, hey, it works!).

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn

\NewDocumentCommand{\quartils}{ O{1em} m }
{
\group_begin:
\masrosid_quartil:nn { #1 } { #2 }
\group_end:
}

\NewDocumentCommand{\quartilD}{ o m }
{
\masrosid_quartil_D:nn { #1 } { #2 }
}
\NewDocumentCommand{\quartilQ}{ m m }
{
\masrosid_quartil_Q:nn { #1 } { #2 }
}

\dim_new:N \l__masrosid_quartil_sep_dim

\cs_new_protected:Nn \masrosid_quartil:nn
{
\cs_set_eq:NN \D \quartilD
\cs_set_eq:NN \Q \quartilQ
\dim_set:Nn \l__masrosid_quartil_sep_dim { #1 }
#2
}

\cs_new_protected:Nn \masrosid_quartil_D:nn
{
{
\underbrace
{
\seq_set_from_clist:Nn \l_tmpa_seq { #2 }
\seq_use:Nn \l_tmpa_seq { \skip_horizontal:N \l__masrosid_quartil_sep_dim }
}
\tl_if_novalue:nF { #1 } { \sb{\textup{#1}} }
}
}

\cs_new_protected:Nn \masrosid_quartil_Q:nn
{
\underset{ \substack { \big\uparrow \\ Q\sb{#1}\mathstrut } }
{
\tl_if_blank:nTF { #2 }
{ \skip_horizontal:N \l__masrosid_quartil_sep_dim }
{
\skip_horizontal:N \l__masrosid_quartil_sep_dim
#2
\skip_horizontal:N \l__masrosid_quartil_sep_dim
}
}
}

\ExplSyntaxOff

\begin{document}

$\quartils{ \D[empat nilai]{2,4,6,6} \Q{2}{7} \D[empat nilai]{9,9,11,12} }$

$\quartils{ \D{2,4} \Q{1}{} \D{6,6} \Q{2}{7} \D{9,9} \Q{3}{} \D{11,12} }$

\end{document}


The parts to be underbraced are given as arguments to \D (for “data”), with an optional argument for the explanatory text. The quartils are denoted by \Q, where the first argument is the quartil number, whereas the second argument is the data (if empty, the spacing will be right).

The command \quartils also accepts an optional argument, default 1em, for the spacing between entries. If you call

\quartils[2em]{ \D{2,4} \Q{1}{} \D{6,6} \Q{2}{7} \D{9,9} \Q{3}{} \D{11,12} }


the output would be