1

I want to put upward arrow with text below some elements of an array.

Code:

\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
          a4paper,
          total={170 mm,257 mm},
          left=20 mm,
          top=20 mm,
         }
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{color}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}

\setlength{\parindent}{2em}

\begin{document}

    \indent \textbf{Step 1 :} \hspace{0.2 cm} Weight the given binary number. \\[0.1 cm]
    \[
    \begin{array}{ccccccccccc}
         1 & 0 & 1 & 1 & 0 & 1 & \textbf{.} & 1 & 0 & 1 & 1
    \end{array}
    \]  

\end{document}

With the above code I am getting the following output:

Obtained output

I want the output as follows:

Desired output

Can anyone help me on this?

5

You can use \substack and \textstyle\uparrow. I suggest using a local macro in order to ease input. The \hidewidth bits are to avoid the negative numbers taking up space.

\documentclass[12pt, a4paper]{book}
\usepackage{amsmath,bm}

\begin{document}

\textbf{Step 1:}\quad Weight the given binary number.
\[
  \newcommand{\wt}[2]{%
    \underset{\substack{\textstyle\uparrow\\\hidewidth\mathstrut#2\hidewidth}}{#1}%
  }
  \begin{array}{*{11}{c}}
  \wt{1}{5} & \wt{0}{4} & \wt{1}{3} & \wt{1}{2} & \wt{0}{1} & \wt{1}{0} &
  \bm{.} &
  \wt{1}{-1} & \wt{0}{-2} & \wt{1}{-3} & \wt{1}{-4}
  \end{array}
\]

\end{document}

You can move the definition of \wt in the preamble if you need the construct several times.

enter image description here

| improve this answer | |
3

A solution with TikZ, just for the sake of completeness

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,arrows}
\begin{document}
\begin{tikzpicture}
\matrix(mybinary)[matrix of math nodes, nodes in empty cells, row sep=1em,column sep=.5em]{%
 1 & 0 & 1 & 1 & 0 & 1 & \textbf{.} & 1  & 0  &  1 & 1  \\
 5 & 4 & 3 & 2 & 1 & 0 &            & -1 & -2 & -3 & -4 \\
};
\foreach\x in {1,2,...,6}{
\draw[<-] (mybinary-1-\x) -- (mybinary-2-\x); 
};
\foreach\x in {8,9,...,11}{
\draw[<-] (mybinary-1-\x) -- (mybinary-2-\x); 
};
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
2

Using the amsmath package you can try something like this:

\usepackage{amsmath}

\begin{tabular}{ccccccccccc}
    $\underset{5}{\stackrel{1}{\uparrow}}$ & $\underset{4}{\stackrel{0}{\uparrow}}$ & $\underset{3}{\stackrel{1}{\uparrow}}$ & $\underset{2}{\stackrel{1}{\uparrow}}$ & $\underset{1}{\stackrel{0}{\uparrow}}$ & $\underset{0}{\stackrel{1}{\uparrow}}$ & \textbf{.} & $\underset{-1}{\stackrel{1}{\uparrow}}$ & $\underset{-2}{\stackrel{0}{\uparrow}}$ & $\underset{-3}{\stackrel{1}{\uparrow}}$ & $\underset{-4}{\stackrel{1}{\uparrow}}$
\end{tabular}

Is a little bit messy but you can get somthing like this:

enter image description here

| improve this answer | |
1

How do you like

\documentclass{book}

\begin{document}
\[
  \begin{array}{ccccccccccc}
    1 & 0 & 1 & 1 & 0 & 1 & \textbf{.} & 1 & 0 & 1 & 1 \\
    \uparrow &\uparrow &\uparrow &\uparrow &\uparrow &\uparrow &&
    \uparrow &\uparrow &\uparrow &\uparrow \\
    5 & 4 & 3 & 2 & 1 & 0&&
    -1&-2&-3&-4
  \end{array}
\]
\end{document}

which results in

enter image description here

| improve this answer | |

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.