2

How to add line between cells in tabular like on this image between 38 and 77 in LaTeX?

I have only this code, that draws table:

\documentclass{scrartcl}

\begin{document}

\begin{tabular}{ |c|c|c|c|c|c|c|c|c|c|c|c|c| }
\hline
23 & 18 & 41 & 38 & 73 & 56 & 52 & 91 & 77 & 60 & 95 & 87 & 64\\ 
\hline
\end{tabular}

\end{document}
2

Here I introduce \mybox{number} and \connect{start}{mid}{end} to accomplish the task. I use \ignorespaces so that you don't have to remember to keep adding % signs everywhere.

The underbar height and rule thickness are controlled by \rlht and \rlwd, respectively. Works for boxed content of any width (e.g., \mybox{1} and \mybox{1248} both work).

\documentclass{article}
\usepackage{stackengine}
\newsavebox\tmpbox
\def\rlht{1ex}    \def\rlwd{.8pt}
\newcommand\vstrut{\smash{\makebox[0pt]{\rule{\rlwd}{\rlht}}}}
\def\conR#1{%
  \savebox\tmpbox{#1}%
  \stackunder[\dimexpr\rlht-\rlwd\relax]{\usebox{\tmpbox}}{%
    \rule{.5\wd\tmpbox}{0pt}\vstrut\rule{.5\wd\tmpbox}{\rlwd}}%
}
\def\conL#1{%
  \savebox\tmpbox{#1}%
  \stackunder[\dimexpr\rlht-\rlwd\relax]{\usebox{\tmpbox}}{%
    \rule{.5\wd\tmpbox}{\rlwd}\vstrut\rule{.5\wd\tmpbox}{0pt}}%
}
\def\conM#1{%
  \savebox\tmpbox{#1}%
  \stackunder[\dimexpr\rlht-\rlwd\relax]{\usebox{\tmpbox}}{%
    \rule{\wd\tmpbox}{\rlwd}}%
}
\newcommand\connect[3]{\conR{#1}\conM{#2}\conL{#3}\ignorespaces}
\newcounter{Index}
\def\mybox#1{%
  \stackon[1pt]{\fbox{#1}}{\scriptsize\arabic{Index}}%
  \stepcounter{Index}%
  \kern-\fboxrule%
  \ignorespaces%
}
\begin{document}
\mybox{23}\mybox{18}\mybox{41}
\connect{\mybox{38}}{\mybox{73}\mybox{56}\mybox{52}\mybox{91}}{\mybox{77}}
\mybox{60}\mybox{95}\mybox{87}\mybox{64}
\end{document}

enter image description here

0

Another solution, with TikZ.

Code

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
  \matrix(m)[matrix of nodes, 
    row sep=-\pgflinewidth, column sep=-\pgflinewidth, nodes={draw},
  ]{
    23 & 18 & 41 & 38 & 73 & 56 & 52 & 91 & 77 & 60 & 95 & 87 & 64\\ 
  };
  \draw[very thick](m-1-1.north west)rectangle(m-1-13.south east); % border
  \foreach \i in {1,...,13}{
    \pgfmathparse{\i-1}
    \node[at=(m-1-\i.north),anchor=south,font=\footnotesize]{\pgfmathprintnumber{\pgfmathresult}};
  }
  \draw(m-1-4.south)|-+(0,-5pt)-|(m-1-9.south);
\end{tikzpicture}
\end{document}

Output

enter image description here

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.