11

I want to write the mathematics inside the box as written below.

enter image description here

See my code given below:

\documentclass{article}

\begin{document}
\\fbox{text}
\framebox[width][pos]{text}

\makebox[\textwidth]{X_1 X_2} \par
\makebox[\textwidth]{X_3 X_4} \par
\cdots
\makebox[\textwidth]{X_4 X_6} \par

\end{document}

Question: I want to write the above maths, How to write it properly?

  • 1
    Before asking a new question, if you think the answers useful (incl. answers to your past questions), then consider accepting it by clicking the tick mark below the voting mark. – Raaja_is_at_topanswers.xyz Feb 02 '19 at 08:37

3 Answers3

19

You can use \boxed command from amsmath package

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{equation*}
    X=\boxed{X_1 X_2}\quad \boxed{X_3 X_4}\cdots\boxed{X_5 X_6}
\end{equation*}



\end{document}

enter image description here

To add colors and labels below boxes

\documentclass{article}
\usepackage{amsmath,tcolorbox}
\tcbuselibrary{theorems,skins}
\usetikzlibrary{arrows.meta}

\newlength\mylabelshift
\setlength\mylabelshift{3mm} % to be adjusted if needed

\newcommand{\drawlabel}[1]{\draw[Stealth-Stealth]([yshift=-\mylabelshift]frame.south west)--node[fill=white]{\(#1\)}([yshift=-\mylabelshift]frame.south east);}
\newtcbox{\mymathbox}[1][l]{
               enhanced,
               nobeforeafter,
               math upper,
               tcbox raise base,
               colback=blue!30, % to set background color
               size=small,
               geometry nodes,
               overlay={\drawlabel{#1}},
               tcbox width=minimum center,
               width= 2 cm ,% to be adjusted if needed
               }
\begin{document}

\begin{equation*}
    X=\mymathbox{X_1 X_2}\quad \mymathbox{X_3 X_4 X_5}\cdots\mymathbox{X_5 X_6}
\end{equation*}
\vspace{1cm}
\begin{equation*}
    X=\mymathbox[a]{X_1 X_2}\quad \mymathbox[b]{X_3 X_4}\cdots\mymathbox[c]{X_5 X_6}
\end{equation*}


\end{document}

enter image description here

11

Depends on how fancy you want to go. In principle you do not need any packages for that.

\documentclass{article}
\begin{document}
\[
 X=
 \raisebox{-1.5ex}{$\begin{array}{c}
 \hline
 \multicolumn{1}{|c|}{X_1 X_2}\\
 \hline
 \leftarrow\ell\rightarrow\\
 \end{array}$}~
 \raisebox{-1.5ex}{$\begin{array}{c}
 \hline
 \multicolumn{1}{|c|}{X_3 X_4}\\
 \hline
 \leftarrow\ell\rightarrow\\
 \end{array}$}\cdots
 \raisebox{-1.5ex}{$\begin{array}{c}
 \hline
 \multicolumn{1}{|c|}{X_5 X_6}\\
 \hline
 \leftarrow\ell\rightarrow\\
 \end{array}$}
\]

\end{document}

enter image description here

3

Here's a package-free version (amsmath is always needed if one does math).

\documentclass{article}
\usepackage{amsmath}

\newcommand{\block}[2]{%
  \begin{array}[t]{@{}c@{}}
  \boxed{\mathstrut #1}\\
  \scriptstyle\blockleftarrowfill\,#2\,\blockrightarrowfill
  \end{array}%
}
\newcommand{\blockleftarrowfill}{%
 \mathord\leftarrow
 \mkern -7mu
 \cleaders\hbox{$\scriptstyle\mkern -2mu\smash-\mkern -2mu$}\hfill
 \mkern -7mu\smash-%
}
\newcommand{\blockrightarrowfill}{%
  \smash-%
  \mkern -7mu
  \cleaders\hbox{$\scriptstyle\mkern -2mu\smash-\mkern -2mu$}\hfill
  \mkern -7mu
  \mathord\rightarrow
}

\begin{document}

\[
X= \block{x_1\ x_2\quad}{l}\quad
   \block{x_3\ x_4\quad}{l}\quad
   \cdots\quad
   \block{x_5\ x_6\quad}{l}
\]

\end{document}

enter image description here

egreg
  • 1,121,712