[Tex/LaTex] Make a C programming language array in LaTeX

programmingtables

Im wondering if I can do some kind of table in LaTeX in order to show my C array nicely in text? I did something like this in KolourPaint:

enter image description here

Tried to do the same with LaTeX tables, but with no success … Is it even possible?

I have only something like this so far (not very impressive, I know):

\documentclass[11pt]{article}
\begin{document}

\begin{table}[ht]
\begin{center}
\begin{tabular}{|c|c|}
    \multicolumn{2}{c}{tab[0]  tab[1]}\\ \hline
    123 & 23 \\ \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

Best Answer

This is far from okey. But it works. I hope someone comes with a more automatized version (I would even prefer TikZ for this over my solution). EDIT I was silly enough to make first and last line with \multicolumn while it's easier to use it just in the middle row. I keep this unchanged, since I'm not fond (:P) of this solution.

\documentclass{scrartcl}

\begin{document}
\begin{tabular}{|c|c|c|}
    \multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} \\ \hline
    c & d & e \\ \hline
    \multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g}
\end{tabular}
\end{document}

enter image description here


And here goes something to play with tap, which can break some things as it mixes Plain Tex with Latex, but… I like the output (I also used it here).

\documentclass{scrartcl}
\input{tap}

\begin{document}
\begintable
    \begintableformat
        & \center
    \endtableformat
    \B": \texttt{tab[0]} " \texttt{tab[1]} " \texttt{tab[2]} " \texttt{tab[3]} " \texttt{tab[4]} " \texttt{tab[5]} " \texttt{tab[6]} " \texttt{tab[7]} \E"
    \=
    \B!: 1234 ! 56 ! 1212 ! 33 ! 1434 ! 80 ! 1312 ! 78 \E!
    \=
    \B": 65508 " 65510 " 65512 " 65514 " 65516 " 65518 " 65520 " 65522 \E"
\endtable
\end{document}

enter image description here